欢迎来到天天文库
浏览记录
ID:51850634
大小:17.55 KB
页数:9页
时间:2020-03-17
《微信小程序列表渲染开发教程.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、微信小程序列表渲染具体开发方法:wx:for在组件上使用wx:for控制属性绑定一个数组,即可使用数组中各项的数据重复渲染该组件。默认数组的当前项的下标变量名默认为index,数组当前项的变量名默认为item{{index}}:{{item.message}}Page({data:{array:[{message:'foo',},{message:'bar'}]}})使用 wx:for-item 可以指定数组当前元素的变量名,使用 wx:for-index 可以指定数组当前下标的变量名
2、:{{idx}}:{{itemName.message}}wx:for也可以嵌套,下边是一个九九乘法表{{i}}*{{j}}={{i*j}}
3、blockwx:for类似blockwx:if,也可以将wx:for用在标签上,以渲染一个包含多节点的结构块。例如:{{index}}:{{item}}wx:key如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如 中的输入内容, 的选中状态),需要使用 wx:key 来指定列表中项目的唯一的标识
4、符。wx:key 的值以两种形式提供.字符串,代表在for循环的array中item的某个property,该property的值需要是列表中唯一的字符串或数字,且不能动态改变。.保留关键字 *this 代表在for循环中的item本身,这种表示需要item本身是一个唯一的字符串或者数字,如:当数据改变触发渲染层重新渲染的时候,会校正带有key的组件,框架会确保他们被重新排序,而不是重新创建,以确保使组件保持自身的状态,并且提高列表渲染时的效率。如不提供 wx:key,会报一个 warning,如果明确知道该列表是静态,或者不必关注其顺序,可以选
5、择忽略。示例代码:{{item.id}}SwitchAddtothefront{{item}}6、tonbindtap="addNumberToFront">AddtothefrontPage({data:{objectArray:[{id:5,unique:'unique_5'},{id:4,unique:'unique_4'},{id:3,unique:'unique_3'},{id:2,unique:'unique_2'},{id:1,unique:'unique_1'},{id:0,unique:'unique_0'},],numberArray:[1,2,3,4]},switch:function(e){const7、length=this.data.objectArray.lengthfor(leti=0;i8、:this.data.objectArray})},addToFront:function(e){constlength=this.da
6、tonbindtap="addNumberToFront">AddtothefrontPage({data:{objectArray:[{id:5,unique:'unique_5'},{id:4,unique:'unique_4'},{id:3,unique:'unique_3'},{id:2,unique:'unique_2'},{id:1,unique:'unique_1'},{id:0,unique:'unique_0'},],numberArray:[1,2,3,4]},switch:function(e){const
7、length=this.data.objectArray.lengthfor(leti=0;i8、:this.data.objectArray})},addToFront:function(e){constlength=this.da
8、:this.data.objectArray})},addToFront:function(e){constlength=this.da
此文档下载收益归作者所有