[英]Changing property values from within the component in Ember
我想知道如何從組件中動態編輯組件屬性。 代碼可能會幫助您更清楚地了解我正在嘗試做什么。
模板/ boards.hbs
<div>
{{board-component title='Title that wants to be dynamic'}}
</div>
組件/板component.hbs
{{#if isEditing}}
<div>
<input type="text" value={{title}}>
</div>
{{else}}
<div>
{{title}}
</div>
{{/if}}
我是否正確地說標准行為會使我在輸入中指定的值反映為標題,但由於我已經在模板中聲明了它恢復到此聲明值的事實?
我怎么能繞過這個?
<input type="text" value={{title}}>
這意味着,board-component title
屬性將從boards.hbs獲取值。 最初,這將顯示在輸入中。 但是更改輸入值不會將其反映在組件的title
屬性中。
但如果您使用如下的輸入助手,
{{input type="text" value=title}}
它是輸入值和title屬性之間的雙向綁定。 因此,每當您從輸入中更改將反映在組件中的值時。
所以回答你的問題,使用輸入助手。
{{input type="text" value=title}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.