简体   繁体   English

在Ember中更改组件内的属性值

[英]Changing property values from within the component in Ember

I'm wondering how I'd go about dynamically editing a component property from within the component. 我想知道如何从组件中动态编辑组件属性。 Code might help you get a bit more clarity on what I'm trying to do. 代码可能会帮助您更清楚地了解我正在尝试做什么。

Templates/boards.hbs 模板/ boards.hbs

<div>
  {{board-component title='Title that wants to be dynamic'}}
</div> 

Components/board-component.hbs 组件/板component.hbs

{{#if isEditing}}

  <div>
    <input type="text" value={{title}}>
  </div>

{{else}}

  <div>
    {{title}}
  </div>

{{/if}}

Am I right in saying that standard behaviour would have the value I specify in the input reflect as the title, but due to the fact that I've declared the value in the template it reverts back to this declared value? 我是否正确地说标准行为会使我在输入中指定的值反映为标题,但由于我已经在模板中声明了它恢复到此声明值的事实?

How can I get around this? 我怎么能绕过这个?

<input type="text" value={{title}}>

It means, board-component title property will get values from boards.hbs. 这意味着,board-component title属性将从boards.hbs获取值。 and initially, this will be displayed in the input. 最初,这将显示在输入中。 but changing input value will not reflect it in title property of the components. 但是更改输入值不会将其反映在组件的title属性中。

But if you used input helper like below, 但如果您使用如下的输入助手,

{{input type="text" value=title}} 

It is two way binding between input value and title property. 它是输入值和title属性之间的双向绑定。 so whenever you change value from input that will reflect in components. 因此,每当您从输入中更改将反映在组件中的值时。

So answer to your question, use input helper. 所以回答你的问题,使用输入助手。

{{input type="text" value=title}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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