接个吻. 2021-08-15 09:21 采纳率: 93.1%
浏览 211
已结题

微信小程序for循环怎么用item


wxml

      <swiper-item wx:for="{{banneritem}}">
        <image src="{{bannerurl}}"></image>
      </swiper-item>

javascript

if (res.data.code == 0) {
          // console.log(res);
          for(let i =0;i< res.data.messge.length ; i++){
            urlImg += res.data.messge[i].For_img;
          }
          _this.setData({
            banneritem : res.data.messge.length,
          })
          console.log(urlImg);
        }

代码如上,我有4个数据,的确是遍历出来了4个内容,但图片全部是一样的,全部是第一张,微信小程序好像没有[i++]这个,我查了网上方法都是用item,但都没看懂,请指点

  • 写回答

5条回答 默认 最新

  • CSDN专家-Time 2021-08-15 09:26
    关注

    你的对象指定的不对,wx:for之后还有 wx:key

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 8月24日
  • 已采纳回答 8月16日
  • 修改了问题 8月15日
  • 创建了问题 8月15日