What is two way binding?

后端 未结 5 1328
后悔当初
后悔当初 2020-11-27 09:32

I have read lots that Backbone doesn\'t do two way binding but I don\'t exactly understand this concept.

Could somebody give me an example of how two way binding wor

5条回答
  •  暖寄归人
    2020-11-27 09:52

    Actually emberjs supports two-way binding, which is one of the most powerful feature for a javascript MVC framework. You can check it out where it mentioning binding in its user guide.

    for emberjs, to create two way binding is by creating a new property with the string Binding at the end, then specifying a path from the global scope:

    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);
    App.wife.get('householdIncome'); // 90000
    

    Note that bindings don't update immediately. Ember waits until all of your application code has finished running before synchronizing changes, so you can change a bound property as many times as you'd like without worrying about the overhead of syncing bindings when values are transient.

    Hope it helps in extend of original answer selected.

提交回复
热议问题