微信小程序 wx:for、wx:for-items和wx:for-item的正确用法

注意:本文转自    https://blog.csdn.net/jimolangyaleng/article/details/54315974

 

 

wx:for = "{{list}}" 用来循环数组

如果是一维数组,实例:

 

  1.  <view wx:for="{{list}}">
  2.          {{index}} {{item.name}}  
  3.  </view>


以上代码中item即为list的别名。

如果是二维或多维数组:

 

  1.  <view wx:for="{{parentList}}">  
  2.    {{item.id}} 
  3.   <view wx:for="{{item.childList}}"  wx:for-item="items"> 
  4.              {{items.name}}{{item.account}}
  5.         </view> 
  6.  </view>


如果将wx:for = "{{list}}"换成wx:for-items="{{list}}";运行科一看到和wx:for = "{{list}}"一样的结果。但是换成wx:for-item = "{{list}}"则循环不出结果。

所以总结如下:

wx:for等价与wx:for-items是循环数组用的;而wx:for-item则是给列表赋别名用的

posted @ 2018-08-23 18:21  boboweiqi93  阅读(19462)  评论(0编辑  收藏  举报