xiaolingxiao
xiaolingxiao

Reputation: 4895

What is the correct syntax for manually setting up one way binding in Ember.js?

I read the documentation as well as the source but am still confused by both. Any ideas?

Upvotes: 2

Views: 361

Answers (1)

chrixian
chrixian

Reputation: 2811

Ember.Binding(to, from).oneWay().connect(obj) is how you'd directly create one however there is an alias Ember.oneWay(obj, to, from) which does the same thing .. an example usage:

App.aObject = Ember.Object.create({
    val: "blah blah"
});

App.bObject = Ember.Object.create({
    val: ""
});

Ember.oneWay(App, 'bObject.val', 'aObject.val');

Ember.get('App.bObject.val'); // => "blah blah"

You can capture that Ember.oneway() into a variable to use for manual disconnecting the binding later but usually I just use Ember's behind the scenes sorcery to create the binding binding creation by ending the value in 'Binding', so we end up with:

App.aObject = Ember.Object.create({
    val: "blah blah"
});

App.bObject = Ember.Object.create({
    valBinding: Ember.Binding.oneWay('App.aObject.val');
});

Ember.get('App.bObject.val'); // => "blah blah"

Upvotes: 6

Related Questions