<p>1.定义</p><p>通俗来说,</p><p>wx:for 这个是正常的循环,没什么可说的。</p><p>wx:for-item=‘变量名(随便起的)’ 它是指定循环数据当前的变量名,可以通过 {{变量名.属性}} 展示数组的元素。</p><p>wx:for-index=‘变量名(随便起)’,它是指向当前元素的下标名,可以在其他事件中定义自定义事件(data-xxx=&#39;{{变量名}}&#39;,,该自定义属性可以在参数e下面打印出来)获取该下标。</p><p>2.用法。</p><p>wx:for-item用法。</p><p>&lt;view class=&#39;content&#39; wx:for=&#39;{{ item.product_list }}&#39; wx:key=&#39;index&#39; wx:for-index=&quot;bindex&quot; wx:for-item=&#39;product_list&#39;&gt;</p><p>&lt;view class=&#39;content_left&#39;&gt;</p><p>&lt;image class=&#39;select_img&#39; src=&quot;{{isSelect?&#39;/img/check_select.png&#39;:&#39;/img/check_btn.png&#39;}}&quot; bindtap=&#39;switchSelect&#39; data-aindex=&#39;{{aindex}}&#39; data-bindex=&#39;{{bindex}}&#39;&gt;&lt;/image&gt;</p><p>&lt;view class=&#39;product_img&#39;&gt;</p><p>&lt;image src=&#39;/img/banner.gif&#39;&gt;&lt;/image&gt;</p><p>&lt;text class=&#39;product_title&#39;&gt;{{ product_list.spac }}&lt;/text&gt;</p><p>&lt;/view&gt;</p><p>&lt;/view&gt;</p><p>定义名称,使用时跟对象一样。</p><p>wx:for-index用法。</p><p>&lt;view class=&#39;content&#39; wx:for=&#39;{{ item.product_list }}&#39; wx:key=&#39;index&#39; wx:for-index=&quot;bindex&quot; wx:for-item=&#39;product_list&#39;&gt;</p><p>&lt;view class=&#39;content_left&#39;&gt;</p><p>&lt;image class=&#39;select_img&#39; src=&quot;{{isSelect?&#39;/img/check_select.png&#39;:&#39;/img/check_btn.png&#39;}}&quot; bindtap=&#39;switchSelect&#39; data-aindex=&#39;{{aindex}}&#39;</p><p> data-bindex=&#39;{{bindex}}&#39;&gt;&lt;/image&gt;</p><p>上边定义完之后,下面可以通过自定义属性获取该下标,并可通过e.xx进行数据的获取。</p><p>数据的获取:</p><p><img src="/up_pic/201906/260834489814.png" title="260834489814.png" alt="1.png"/></p>
RangeTime:0.003733s
RangeMem:197.83 KB
返回顶部 留言