search
HomeWeChat AppletMini Program DevelopmentList rendering of WeChat applet example introduction

This article brings you relevant knowledge about WeChat Mini Program, which mainly introduces the relevant content about list rendering. Let’s take a look at it together. I hope it will be helpful to everyone.

List rendering of WeChat applet example introduction

【Related learning recommendations: 小program learning tutorial

wx:for

Through wx:for You can loop to render repeated component structures based on the specified array. The syntax example is as follows:

<view> 
    索引是:{{index}} 当前项是:{{item}}
</view>

By default, the index of the current loop item is represented by index; the current loop item is represented by item hacker.wxml Define a for loop to access the array

<view> 
    索引是:{{index}} 当前项是:{{item}}
</view>

hacker.js Define an array

Page({    data:{        arr1:['a','b','c']
    }
})

The running results are as follows:

List rendering of WeChat applet example introduction

Manually specify the index and variable name of the current item

Use wx:for-index A variable name that specifies the index of the current loop item Use wx:for-item to specify the variable name of the current item The sample code is as follows:

<view>
    索引是:{{idx}}  当前项是:{{itemName}}
</view>

hacker.wxml

<view>
    索引是:{{idx}}  当前项是:{{itemName}}
</view>

hacker.js

Page({    data:{        arr1:['a','b','c']
    }
})

The running results are as follows: List rendering of WeChat applet example introduction

wx:key usage

Similar to :key in Vue list rendering, when the applet implements list rendering, it is also recommended to specify a unique key value for the rendered list items to improve rendering efficiency. The sample code is as follows: hacker.wxml

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

hacker.js

Page({    data:{        userList:[
            {id: 1,name: 'hacker'},
            {id: 2,name: 'meng'},
            {id: 3,name: 'yuan'}
        ]
    }
})

The running results are as follows: List rendering of WeChat applet example introduction[Related learning recommendations: 小program learning tutorial]

The above is the detailed content of List rendering of WeChat applet example introduction. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:掘金. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor