Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Does anyone tried oneway binding in ember.js? It is not working for me.

Here is my snippet.

App.UserController = Ember.ObjectController.extend({
    user : { "name" : "Albert"} ,
    userCopyBinding: Ember.Binding.oneWay("this.user"); 
});

In handlebars:

 <label>user name </label>
 {{view Ember.TextField  valueBinding="userCopy.name"}}

 <label>fist name is {{user.name}}</label>

If I Enter text in the input it changes the 'user's name' also. Am I doing wrong here?

share|improve this question
1  
You have a typo, it should be, Ember.Binding.oneWay. – Darshan Sawardekar 1 hour ago
@DarshanSawardekar, Thanks, Now I corrected my typo. I think the oneway binding is not working for objects. Right? – NkS 54 mins ago

1 Answer

In your comments you stated:

I think the oneway binding is not working for objects. Right?

Yes right. As stated in the guides:

A binding creates a link between two properties such that when one changes, the other one is updated to the new value automatically. Bindings can connect properties on the same object, or across two different objects. Unlike most other frameworks that include some sort of binding implementation, bindings in Ember.js can be used with any object, not just between views and models.

So, yes oneWay binding only works for properties and not objetcs.

Change your code to this to make it work:

App.UserController = Ember.ObjectController.extend({
  user : { "name" : "Albert"} ,
  userNameBinding: Ember.Binding.oneWay("this.user.name"); 
});

In the template then:

<label>user name </label>
  {{view Ember.TextField valueBinding="userName"}}

<label>fist name is {{userName}}</label>

Hope it helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.