从云数据库获取的数据res.data:
- {_id: "W88iVpL-scb2HabB", collect_type: "poem", poem_author: "王安石", poem_dynasty: "宋代", …}
- :{_id: "W88ivFw3CBlYln8u",collect_type: "poem", poem_author: "曹操", poem_dynasty: "两汉", …}
转换代码js:
// console.log('[数据库] [查询记录] 成功: ', res.data)
console.log('res.data: ', res.data)
var _collections = new Array()
for (var i = 0; i < res.data.length; i++) {
// console.log(i, res.data[i])
_collections.push(JSON.parse(JSON.stringify(res.data[i])))
}
for (var j = 0; j < _collections.length; j++) {
console.log("_collections["+j+"]="+ _collections[j])
// _collections.push(JSON.parse(res.data[i]))
}
this.setData({
collections:_collections,
})
布局文件wxml:
<view>
<view wx:for="{{collections}}" wx:key="id">
{{item.poem_id}} | {{item.poem_title}} | {{item.poem_author}} | {{item.poem_dynasty}}
</view>
</view>
最终转换的结果: