根据 Ember指南,这个片段应该设置实例的houseHoldIncome
属性。App.wife
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'));
});
这将输出更新的收入。