One-way binding in handlebars template?

It doesn’t appear possible to create one-way bindings within a handlebars template, is that correct?

The binding documentation shows how to create one-way bindings within a view class (ie, in JavaScript), but there doesn’t appear to be a “shortcut” like:

{{ view App.MyView userNameOneWayBinding="user.fullName" }}

I have a view that will open a modal window that allows users to search. I want to pass values to this view, but I don’t want to pass any changes back to the parent view (since they might change the original values in their search). The Ember.Binding.oneWay code seems less re-usable, as I need the view needs to know the property “path” within the parent view. For instance, the path could be “user.fullName” in one view but “otherUser.AliasName” in another.

Would the above “shortcut” syntax by useful to anyone else or have gone on a weird tangent? I’m still very new to Ember (in case that wasn’t obvious already), so I might be missing something entirely.

1 Like

I think there should be a nicer way to do it. I asked a similar question in Stack Overflow. A possible solution is to have a view property for you to delegate to and crete the binding manually there.

{{ view App.MyView userNameBinding="user.fullName" }}

Then in your view you would have two properties. One that is used externally (userName) and one to be used within the view that can change. Then you can bind them using a oneWay or a computer property.

var MyView = Ember.View.extend({
  userName: '', 
  internalUserNameBinding: Ember.Binding.oneWay('userName')
});