Skip to content

Commit

Permalink
update wx:key
Browse files Browse the repository at this point in the history
  • Loading branch information
huajingwen@didiglobal.com committed May 14, 2024
1 parent 1972937 commit 30368a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 1 addition & 11 deletions packages/webpack-plugin/lib/platform/template/wx/index.js
Expand Up @@ -6,14 +6,6 @@ const isValidIdentifierStr = require('../../../utils/is-valid-identifier-str')
const { parseMustacheWithContext, stringifyWithResolveComputed } = require('../../../template-compiler/compiler')
const normalize = require('../../../utils/normalize')

function convertKeyReact ({ value }, { el }) {
const itemName = el.attrsMap['wx:for-item'] || 'item'
return {
name: 'key',
value: `{{this.__getWxKey(${itemName}, '${value}')}}`
}
}

module.exports = function getSpec ({ warn, error }) {
const spec = {
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ios', 'android'],
Expand Down Expand Up @@ -117,9 +109,7 @@ module.exports = function getSpec ({ warn, error }) {
name: ':key',
value
}
},
ios: convertKeyReact,
android: convertKeyReact
}
},
{
// 在swan/web模式下删除for-index/for-item,转换为v/s-for表达式
Expand Down
7 changes: 7 additions & 0 deletions packages/webpack-plugin/lib/template-compiler/compiler.js
Expand Up @@ -1751,6 +1751,13 @@ function postProcessFor (el) {

function postProcessForReact (el) {
if (el.for) {
if (el.for.key) {
addExp(el, `this.__getWxKey(${el.for.item}, '${el.for.key}')`, false, 'key')
addAttrs(el, [{
name: 'key',
value: el.for.key
}])
}
popForScopes()
}
}
Expand Down

0 comments on commit 30368a5

Please sign in to comment.