微信小程序 Now you can provide attr "wx:key" for a "wx:for" to improve performance.
2017-05-18 15:29
981 查看
看文章 扫一扫 领红包哦
是一个关于性能优化方面的提示.
wx:key
如果列表中项目的位置会动态改变或者有新的项目添加到列表中,并且希望列表中的项目保持自己的特征和状态(如<input/>中的输入内容,
<switch/>的选中状态),需要使用
wx:key来指定列表中项目的唯一的标识符。
wx:key的值以两种形式提供
字符串,代表在 for 循环的 array 中 item 的某个 property,该 property 的值需要是列表中唯一的字符串或数字,且不能动态改变。
保留关键字
*this代表在 for 循环中的 item 本身,这种表示需要 item 本身是一个唯一的字符串或者数字,如:
当数据改变触发渲染层重新渲染的时候,会校正带有 key 的组件,框架会确保他们被重新排序,而不是重新创建,以确保使组件保持自身的状态,并且提高列表渲染时的效率。
如不提供
wx:key,会报一个
warning, 如果明确知道该列表是静态,或者不必关注其顺序,可以选择忽略。
相关文章推荐
- 微信小程序开发warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance
- [微信小程序]控制台弹出 warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance
- 微信小程序----wx:key(Now you can provide attr "wx:key" for a "wx:for" to improve performance.)
- Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- 警告Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- 微信小程序的wx:for,wx:for-items,wx:for-item,wx:key等的关系及正确使用
- "Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
- gdb提示“you can't do that without a process to debug"解决方法
- Error:Execution failed for task ':app:packageRelease'. > Failed to read key brautyfarm from store "G
- 微信小程序 wx:key详细介绍
- Plan for apps for SharePoint 2013(You need to ensure that users can install apps from the App Catal)
- eclipse运行程序显示the user operation is waiting for "building workspace" to complete
- 安装Visual Studio 2010时提示"The location specified for the help content store is invalid or you do not have access to it".
- Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option)
- iOS9.0 canOpenURL: failed for URL: "xx" - error:"This app is not allowed to query for scheme xx"key>
- 微信小程序入门教程 - 列表渲染多层嵌套循环及wx:key的使用