ember.js - How to set up bindings in Ember -


i saw in ember documentation set binding using similar snippet:

householdincomebinding: 'app.wife.householdincome' 

however set bindings supplying objects instead of strings (path global scope). need achieve similar this:

ember.bind(obj1, "obj1attributename", obj2, "obj2attributename"); 

suggestions welcome. thanks!

bindings can connected directly 1 object. from , to paths evaluated relative object they're connected. these paths can global.

check out docs , implementation ember.bind helper:

/**   global helper method create new binding. pass root object   along `to` , `from` path create , connect binding.    @method bind   @for ember   @param {object} obj root object of transform.   @param {string} path 'to' side of binding.     must relative obj.   @param {string} path 'from' side of binding.     must relative obj or global path.   @return {ember.binding} binding instance */ ember.bind = function(obj, to, from) {   return new ember.binding(to, from).connect(obj); }; 

so, you've got decide object want connect binding directly, , how can reference other object. you've got couple options:

a) provide relationship between 2 objects, , use bind() connect relative paths:

obj1.set('friend', obj2); ember.bind(obj1, 'obj1attributename', 'friend.obj2attributename'); 

b) provide global path from side of binding:

app.set('obj2', obj2); // make obj2 accessible app namespace ember.bind(obj1, 'obj1attributename', 'app.obj2.obj2attributename'); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -