WeChat applet multi-layer nested rendering list and data acquisition code

不言
Release: 2018-10-23 16:32:24
forward
5106 people have browsed it

The content of this article is about the code for multi-layer nested rendering lists and data acquisition of WeChat mini programs. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Cause: The intention is to achieve an effect similar to Android viewpager, and I thought of using the swiper component of the WeChat applet, but if only one wx:for is used in each swiper-item to render Data is really too slow, so I thought of multi-layer nested data rendering to improve efficiency.

Go directly to the code

wxml:

<view>
  <view>----{{item.name}}----</view>
  <view>

    <view>----{{two.name}}----</view>
  </view>
  <view>
    ----{{three.name}}----
  </view>
 -------------------------------------------
</view>
Copy after login

js

    one: [{
        id: 1,
        name:'第一层',
        two: [{
          'id': 11,
          'name': '第二层第一个数据'
        }, {
          'id': 12,
            'name': '第二层第二个数据'
        }],
        three: [{
          'name': '第三层数据'
        }]
      },
      {
        id: 2,
        name: '第二次渲染第一层',
        two: [{
          'id': 13,
          'name': '第二层第一个数据2'
        }, {
          'id': 14,
            'name': '第二层第二个数据2'
        }],
        three: [{
          'name': '第三层数据'
        }]
      },
      {
        id: 3,
        name: '第三次渲染第一层',
        two: [{
          'id': 15,
          'name': '第二层第一个数据3'
        }, {
          'id': 16,
            'name': '第二层第二个数据3'
        }],
        three: [{
          'name': '第三层数据'
        }]
      }
    ]
Copy after login

Implementation renderings:

WeChat applet multi-layer nested rendering list and data acquisition code

If you want to get the value of a field in one of the arrays, you can use the following writing:

    var twodata = this.data.one[0].two
    var text = twodata[1].name
    console.log(text)
Copy after login

WeChat applet multi-layer nested rendering list and data acquisition code

The above is the detailed content of WeChat applet multi-layer nested rendering list and data acquisition code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!