wx:for渲染数组,key不绑定index,在对其绑定的数组排序时会出现index混乱的情况?

小程序 文章 2021-03-03 09:41 526 0 全屏看文

AI助手支持GPT4.0

wx:for渲染数组,key不绑定index,在对其绑定的数组排序时会出现index混乱的情况?Wx:for renders the array, the key is not bound to the index, and the index will be confused when sorting the bound array?

wx:for渲染数组,key不绑定index,在对其绑定的数组排序时会出现index混乱的情况?

回答:

Brother斌🎈:

打一大堆字还不如给个代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

拾忆:

 <block wx:for="{{banners}}" wx:key="id">

 <block wx:for="{{banners}}" wx:key="index">

卢霄霄:

vue的 key写法一般是 item.id,而小程序的写法直接是 id

红狐入梦:

感觉就是算法搞错了排序后原dom所在的位置,大晚上的脑子也转的好慢,想不明白了

-EOF-

AI助手支持GPT4.0