微信小程序系列——循环数组在前后端的使用

先赞后看,此生必赚!

wxml:

使用wx:for之后,需要加入wx:key='{{index}}'来指定下标

如:

<view wx:for='{{list}}' wx:key='{{index}}'>

姓名:{{item.name}},年龄:{{item.age}}

</view>

js:

pageData.forEach(function(item, index){
       console.log(item); //这里的item就是从数组里拿出来的每一个每一组
       that.setData({
           id: item.id,
           title: item.title
       })
})

体验小程序

      

更多内容,请关注公众号:程序员高手之路

在公众号回复:小程序资源   即可免费获取以下微信小程序视频教程!

发布了131 篇原创文章 · 获赞 1663 · 访问量 56万+

猜你喜欢

转载自blog.csdn.net/qq_26230421/article/details/105265491