From 1afae00c4599a18b5e59038aa1d58fab4bf23e04 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 15 May 2025 14:30:37 +1000 Subject: [PATCH] Refactor %for macro handling: dynamically bind key attribute and remove original %key attribute --- src/main.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 6a5bd67..ad73ff3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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)