【问题标题】:Changing property values from within the component in Ember在 Ember 中更改组件内的属性值
【发布时间】:2016-08-04 16:06:16
【问题描述】:

我想知道如何从组件中动态编辑组件属性。代码可能会帮助您更清楚地了解我正在尝试做什么。

模板/boards.hbs

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

组件/board-component.hbs

{{#if isEditing}}

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

{{else}}

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

{{/if}}

我是否正确地说标准行为会将我在输入中指定的值反映为标题,但由于我已经在模板中声明了该值,它会恢复为这个声明的值?

我该如何解决这个问题?

【问题讨论】:

  • 。你没有使用输入助手。所以它不是双向绑定

标签: ember.js


【解决方案1】:
<input type="text" value={{title}}>

这意味着,board-component title 属性将从boards.hbs 中获取值。最初,这将显示在输入中。但更改输入值不会反映在组件的title 属性中。

但如果你使用如下输入助手,

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

输入值和title属性是双向绑定的。因此,每当您更改将反映在组件中的输入值时。

所以回答你的问题,使用输入助手。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 2021-12-25
    相关资源
    最近更新 更多