簡體   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