Refactor %for macro handling: dynamically bind key attribute and remove original %key attribute

This commit is contained in:
Astrian Zheng 2025-05-15 14:30:37 +10:00
parent 719853d2d1
commit 1afae00c45
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -466,10 +466,18 @@ export default (options: ComponentOptions) => {
const itemContext = {
[itemVar]: item
}
if (indexVar) {
if (indexVar)
itemContext[indexVar] = index
// insert %key attribute, which dynamically bind the key
if (keyAttr) {
const keyValue = this._evaluateExpressionWithItemContext(keyAttr, itemContext)
itemElement.setAttribute('data-laterano-key', String(keyValue))
}
// remove original %key attribute
itemElement.removeAttribute('%key')
// Apply the item context to the element
// We will use recursive processing here!
this._processElementWithItemContext(itemElement, itemContext)