繁体   English   中英

Aurelia 使用模板字符串动态绑定变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM