wx:for问题
发布于 5 年前 作者 bzhou 9653 次浏览 来自 问答

<!–页面代码–>

<view class=‘container’>

{{queryResult}}

</view>

<view wx:for=’{{queryResult}}’>

{{item.imgUrl}}  <!–这里拿不到数据–>

</view>

//显示的不对啊

//数据已经返回

//js代码

const app = getApp()

Page({

/**

  * 页面的初始数据

  */

data: {

queryResult: ‘’,

},

/**

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

  */

onLoad: function (options) {

this.onQuery()

},

onQuery: function () {

const db = wx.cloud.database()

db.collection(‘redCultureList’).get({

success: res => {

this.setData({

queryResult: JSON.stringify(res.data, null, 2)

})

console.log(’[数据库] [查询记录] 成功: ', res)

},

fail: err => {

wx.showToast({

icon: ‘none’,

title: ‘查询记录失败’

})

console.error(’[数据库] [查询记录] 失败:’, err)

}

})

}

1 回复

JSON.stringify 返回的是字符串,不是数组

回到顶部