- 当前 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>
求解 求大佬解答
把res.data[i]打印一下,贴图看看
打印出来 是可以打印的 但是就是没显示
求大佬解答
我觉的是你的写法有问题,js那里不用for循环啊,wx:for就是循环啊,直接setData
如果js不用for循环 我怎么和id对比 id就是我页面跳转过来的点击role 我做这个是想要 页面跳转 然后从数据库里面的数组开始筛选数据 放到不同的页面里面 我首先得先获取点击页面的ID 然后和我的数据里面的herotype对比 如果相同 就放进一个数组 然后遍历数组 我是这样的想法 请问大佬有得解救吗