收藏
回答

请问为什么我在前端显示不出来setdata的p1数组

框架类型 问题类型 终端类型 AppID 基础库版本
小程序 Bug 客户端 wx9b478516e359214a 2.6.6

- 当前 Bug 的表现(可附上截图)


- 预期表现


- 复现路径


- 提供一个最简复现 Demo



const db = wx.cloud.database({});

const cont = db.collection('  hero');

Page({


  /**

   * 页面的初始数据

   */

  data: {

    p: [],

    p1: []

    },


 


  /**

   * 生命周期函数--监听页面加载

   */

  onLoad: function (options) {


    db.collection('hero').get({

      success: res => {

        this.setData({

          p: res.data

        })

     //   console.log(res.data[0].herotype)

   //     var pp = this.data.p

    //    const length = pp.length

       

        var id = parseInt(options.role)

        console.log(id)

       for(let i=0;i<=res.data.length;i++){

        // console.log(res.data.length)

         if(id==res.data[i].herotype){  

           this.setData({

             p1: res.data[i]

           })

         

         }


       }

      }

    })  }

<view class='big'>

<view class='list' wx:for="{{p1}}">

    <image class='list-img' src='{{item.img}}'></image>

    <view class='pro-body'>

    <view class='list-item1'>{{item.ename}}</view>

     <view class='list-item1'>{{item.name}}</view>

  </view>

</view>

</view>



回答关注问题邀请回答
收藏

2 个回答

  • 2019-05-12

    求解 求大佬解答

    2019-05-12
    有用 1
    回复
  • x_Qiang
    x_Qiang
    2019-05-12

    res.data[i]打印一下,贴图看看

    2019-05-12
    有用
    回复 10
    • 2019-05-12


      2019-05-12
      回复
    • 2019-05-12回复

      打印出来 是可以打印的 但是就是没显示

      2019-05-12
      回复
    • 2019-05-12

      求大佬解答

      2019-05-12
      回复
    • x_Qiang
      x_Qiang
      2019-05-12回复

      我觉的是你的写法有问题,js那里不用for循环啊,wx:for就是循环啊,直接setData

      2019-05-12
      回复
    • 2019-05-12回复x_Qiang

      如果js不用for循环 我怎么和id对比 id就是我页面跳转过来的点击role 我做这个是想要 页面跳转 然后从数据库里面的数组开始筛选数据 放到不同的页面里面  我首先得先获取点击页面的ID 然后和我的数据里面的herotype对比 如果相同 就放进一个数组 然后遍历数组 我是这样的想法 请问大佬有得解救吗

      2019-05-12
      回复
    查看更多(5)
登录 后发表内容