[英]Aurelia dynamically bound variable with template string
我正在尝试在组件中设置组件的动态id
。
所以子组件有一个可绑定的uniqueId
属性。 父组件有自己的uniqueId
,我试图将其保留在子组件的uniqueId
中,就像遵循 BEM 约定一样:
<text-input-editor repeat.for="boxSide of boxSides"
uniqueId.bind="box-editor-${uniqueId}__${boxSide}-input"></text-input-editor>
但这给了我以下错误:未使用的unconsumed token {
(删节)。
我尝试在https://aurelia.io/docs/templating/custom-elements#declarative-computed-values中使用<let></let>
元素,但这也不起作用。
我不确定如何在视图中执行此操作,因为我宁愿不在控制器级别处理此问题(这只是该视图中的许多组件之一)。
假设 uniqueId 在您的视图模型中有一个值,因为表达式已经具有“.bind”格式,这将是:
<text-input-editor repeat.for="boxSide of boxSides"
uniqueId.bind="'box-editor-' + uniqueId + '__' + boxSide + '-input'"></text-input-editor>
否则,它可能是:
<text-input-editor repeat.for="boxSide of boxSides"
uniqueId="box-editor-${uniqueId}__${boxSide}-input"></text-input-editor>
可以在以下位置查看工作版本:
所以我没有特别尝试 Cristián Ormazábal 的回答,但我通过将uniqueId
更改为unique-id
来解决我的问题:
<text-input-editor repeat.for="boxSide of boxSides"
unique-id="box-editor-${uniqueId}__${boxSide}-input""
></text-input-editor>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.