Ember.js绑定教程
Ember.js Bindings Tutorial
根据 Ember 指南,此代码段应设置 App.wife
实例的 houseHoldIncome
属性。
App.wife = Ember.Object.create({
householdIncome: 80000
});
App.husband = Ember.Object.create({
householdIncomeBinding: 'App.wife.householdIncome'
});
App.husband.get('householdIncome'); // 80000
// Someone gets raise.
App.husband.set('householdIncome', 90000);
console.log(App.wife.get('householdIncome')); // 90000
console.log(App.wife.get('householdIncome'))
仍然输出 80000。这是由于绑定没有立即更新还是我做错了什么?
编辑:
绑定似乎不会立即更新。
App.wife.addObserver('householdIncome', function() {
console.log('Wife income changed: '+App.wife.get('householdIncome'));
});
这将输出更新的收入。
这是预期的行为,因为 ember 使用称为 backburner 的库对一些更改进行排队。这样做的好处是,模型属性中的多个更改(例如在 foreach 中)将只呈现一次。因此,您无需关心观察器和 dom 更新的性能。
如果使用Ember.run.sync()
则可以强制刷新绑定,以便看到正在传播的更改:
App.wife = Ember.Object.create({
householdIncome: 80000
});
App.husband = Ember.Object.create({
householdIncomeBinding: 'App.wife.householdIncome'
});
App.husband.get('householdIncome'); // 80000
// Someone gets raise.
App.husband.set('householdIncome', 90000);
Ember.run.sync();
console.log(App.wife.get('householdIncome')); // 90000
在那把小提琴中,你会看到妻子householdIncome
财产正在更新 http://jsfiddle.net/marciojunior/uCr3C/
相关文章:
- 在VanillaJS中模拟模型双向数据绑定
- 无法通过数组映射绑定
- 主干-不管怎样,检查事件以前是否绑定过
- 用于搜索的聚合物嵌套绑定
- Angular:更新一次性绑定的数据
- 如何使用ngrepeat和双向绑定获得指令的隔离范围
- react.js中的密钥绑定
- 使用regex的jquery keydown绑定不会验证撇号和句点
- 将事件处理程序绑定到任何可能的事件
- AngularJS指令只识别双向绑定类型
- Telerik rad组合框多列数据绑定
- 对API数据使用声明性绑定
- 如何销毁/删除/取消绑定SnapSVG.js
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- 数据绑定:'系统Char'不包含名为'xxxxx'
- react组件中的绑定方法
- 即使使用默认教程,也无法应用淘汰绑定
- Ember.js绑定教程
- 无线电绑定在 knockoutjs 教程中无法按预期工作
- 从教程示例中绑定数据