【问题标题】:Strange behavior in ember 1.13.*ember 1.13.* 中的奇怪行为
【发布时间】:2016-08-03 17:06:36
【问题描述】:

我有一个控制器 ApplicationController 具有 controllerIntcontrollerString 属性。

我有一个组件RedSquareComponent 具有componentIntcomponentString 属性。

我通过 hbs-template、componentString=controllerString="VALUE FROM CONTROLLER"controllerIntcontrollerString 绑定到 componentIntcomponentString

RedSquareComponent 我也有.on('init') 方法将"SET ON INIT" 值设置为componentString

我已经向组件添加了一个动作来处理点击某个对象(红色方块)并将某个值(例如,1)设置为componentInt

但是当这个动作起作用时——componentString 也改变了(我不知道为什么),变成等于"VALUE FROM CONTROLLER"

这真的是预期的行为吗?

相同的代码在 Ember 12.4 上运行良好,但我已经在几个 13.* 版本上检查过 - 它不起作用。

https://jsfiddle.net/AlexeyBedonik/a23ev98w/3/

【问题讨论】:

    标签: ember.js ember-components


    【解决方案1】:

    在您的情况下,如果您只是将.on('init') 部分更改为.on('didInsertElement'),它将解决您的问题。(这意味着它会将控制器和组件componentString 属性更新为“SET ON INIT”。)
    但是您不应该更改已弃用的父级上的值。所以你会收到弃用警告。

    要获取有关此问题/错误的更多信息follow this discussion

    遵循/理解以下概念很好。

    1) 向组件传递属性默认为two-way data binding
    2) 更新数据始终遵循 Data Down Actions Up 原则 (DDAU)

    【讨论】:

      猜你喜欢
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多