如何动态地将 optionValue 附加到属性的输入 id 和标签?
how to append optionValue to the input id and label for attribute dynamically?
假设选项 = ["low"、"medium"、"high"]
{{#each optionValue in options}}
<span>
<input type="radio" id="screen-risk-{{optionValue}}" name="riskRating"/>
<label for="screen-risk-{{optionValue}}" name="checkbox"> Low </label>
</span>
{{/each}}
如何动态地将 optionValue
附加到属性的输入 ID 和标签?
不使用任何助手,它应该像 screen-risk-low, screen-risk-medium, screen-risk-high
绑定属性语法仅在 ember >= 1.11.0
中受支持
为了得到你想要的,在当前版本ember(1.10.0
)。你可以使用 unbound
{{#each optionValue in options}}
<span>
<input type="radio" id="screen-risk-{{unbound optionValue}}" name="riskRating"/>
<label for="screen-risk-{{unbound optionValue}}" name="checkbox"> {{optionValue}} </label>
</span>
{{/each}}
但如文档中所述,如果更改则不会更新:
unbound allows you to output a property without binding. Important: The output will not be updated if the property changes. Use with caution.
看到一个demo
假设选项 = ["low"、"medium"、"high"]
{{#each optionValue in options}}
<span>
<input type="radio" id="screen-risk-{{optionValue}}" name="riskRating"/>
<label for="screen-risk-{{optionValue}}" name="checkbox"> Low </label>
</span>
{{/each}}
如何动态地将 optionValue
附加到属性的输入 ID 和标签?
不使用任何助手,它应该像 screen-risk-low, screen-risk-medium, screen-risk-high
绑定属性语法仅在 ember >= 1.11.0
为了得到你想要的,在当前版本ember(1.10.0
)。你可以使用 unbound
{{#each optionValue in options}}
<span>
<input type="radio" id="screen-risk-{{unbound optionValue}}" name="riskRating"/>
<label for="screen-risk-{{unbound optionValue}}" name="checkbox"> {{optionValue}} </label>
</span>
{{/each}}
但如文档中所述,如果更改则不会更新:
unbound allows you to output a property without binding. Important: The output will not be updated if the property changes. Use with caution.
看到一个demo