You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Aurelia视图内绑定模板字符串生成组件动态id报错如何解决?

报错原因是Aurelia的绑定表达式解析器不支持在.bind属性值中直接使用ES6模板字符串语法,所以会抛出unconsumed token {错误。以下两种视图层写法均可实现需求,不需要修改控制器逻辑:

方案1:使用原生属性插值(推荐)

Aurelia默认支持普通属性内的${}插值解析,不需要额外加.bind修饰符,直接编写即可:

<text-input-editor repeat.for="boxSide of boxSides"
   uniqueId="box-editor-${uniqueId}__${boxSide}-input"></text-input-editor>

方案2:.bind绑定场景下使用字符串拼接

如果需要使用.bind指定绑定模式等特殊需求,把模板字符串替换为普通字符串拼接格式即可:

<text-input-editor repeat.for="boxSide of boxSides"
   uniqueId.bind="'box-editor-' + uniqueId + '__' + boxSide + '-input'"></text-input-editor>

如果要使用<let>元素实现,需注意变量作用域:在repeat循环内使用的变量要将<let>声明放在循环内部,或直接用上述两种更简洁的写法即可。

内容的提问来源于stack exchange,提问作者Moustachiste

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 00:45:06