微信小程序三层嵌套循环

    技术2022-07-11  120

    微信小程序三层嵌套循环

    !!三级嵌套必须在二级里面 !!多层嵌套举一反三

    效果图

    wxml

    <view wx:for="{{list}}" wx:for-item="list" wx:key="id"> <view class="first">一层循环:{{list.first}}</view> <view wx:for="{{list.children}}" wx:for-item="children" wx:key="id"> <view class="sec">二层循环:{{children.sec}}</view> <view wx:for="{{children.grandson}}" wx:for-item="item" wx:key="id"> <view class="third">三层循环:{{item.third}}</view> </view> </view> </view>

    js

    Page({ data: { list:[{ first:'一层第一个', children:[{ sec:'二层第一个', grandson:[{ third:'三层第一个', },{ third:'三层第二个' },{ third:'三层第三个' }] },{ sec:'二层第二个', grandson:[{ third:'三层第四个' },{ third:'三层第五个' },{ third:'三层第六个' }] },{ sec:'二层第三个', grandson:[{ third:'三层第七个' },{ third:'三层第八个' },{ third:'三层第九个' }] }] }], }, onLoad: function (options) { }, })
    Processed: 0.011, SQL: 9