wx:key="字符串" wx:key="*this"

1:wx:key="字符串"

This "string" represents the for loop array in an item of "property"
value of the "property" of the list of needs is the only strings or numbers, and can not be changed dynamically.
When a plurality of components that need to be traversed properties.

 
  1. //test.js
  2. data: {
  3. input_data: [
  4. { id: 1, unique: "unique1" },
  5. { id: 2, unique: "unique2" },
  6. { id: 3, unique: "unique3" },
  7. { id: 4, unique: "unique4" },
  8. ]
  9. }
  10. //test.wxml
  11. <input value="id:{{item.id}}" wx:for="{{input_data}}" wx:key="unique" />

2:wx:key="*this"

Reserved keywords "* this" represents a loop for item itself,
this representation requires item itself is a string or a number unique
to only one component attribute and attribute value unique.

 
  1. //test.js
  2. data: {
  3. numberArray: [1, 2, 3, 4],
  4. stringArray:['aaa','ccc','fff','good']
  5. }
  6. //test.wxml
  7. <input value="id:{{ item }}" wx:for="{{numberArray}}" wx:key="*this" />
  8. <input value="id:{{ item }}" wx:for="{{stringArray}}" wx:key="*this" />
  9. },

Guess you like

Origin www.cnblogs.com/wen-/p/12134628.html