# wxml/no-dot-this-in-wx-key
# Background
*this
If the positions of list items dynamically change or new items are added to the list and you want the items in the list to retain their features and statuses (such as the content input in input and the selection status of switch), you must use wx:key to specify the unique identifiers of the items in the list.
The wx:key is provided in two formats:
- String: Represents a property of an item in the for loop array. The value of this property must be a unique string or number in the list and cannot dynamically change.
- Reserved keyword
*this
: Represents the item itself in the for loop. This expresses that the item itself is a unique string or number.
# Motivation
This rule enforce developer use implicit wx:key
, because not all loop array is string[]
or number[]
.
<!-- ✓ GOOD -->
<view
wx:for="{{goodsList}}"
wx:key="goodsId"
>
{{item.name}}
</view>
<!-- ✗ BAD -->
<view
wx:for="{{goodsList}}"
wx:key="*this"
>
{{item.name}}
</view>
💡 tips
You can edit code via online editor, it's online REPL, try to fix eslint problem !
# Config
No special options, normal config is ok
{ "wxml/no-dot-this-in-wx-key": "error" }
# Version
This rule was introduced in eslint-plugin-wxml v0.2.1