Peter Wang
Peter Wang

Reputation: 21

ember.js: it doesn't work when i use the valueBinding for the array

Controller:
games : Ember.A(["1", "2", "3"]),

View:
{{#each view.games}}
    {{view Ember.TextField valueBinding="this"}}
{{/each}}

when I change the value of the textfield, it didn't change the array at the same time?

Upvotes: 2

Views: 465

Answers (1)

sly7_7
sly7_7

Reputation: 12011

Hum, I feel weird on this... If you use objects in the array, then the bindings works well, with strings, as you do, effectively it's not working...

<script type="text/x-handlebars">
  <h5> work with object </h5>
  {{#each plop in App.controller1}}
    {{view Em.TextField valueBinding="plop.name"}} {{plop.name}}
  {{/each}}
  <h5> don't work with strings </h5>
  {{#each plop in App.controller2}}
    {{view Em.TextField valueBinding="plop"}} {{plop}}
  {{/each}}
</script>  

window.App = Ember.Application.create({
  controller1: Ember.ArrayController.create({
    content: [{name:"aaaa"}, {name:"bbbbb"}, {name:"ccccc"}]
  }),

  controller2: ["aaaa", "bbbbb", "cccc"]       
});​

http://jsfiddle.net/Sly7/SQ5g8/

EDIT: Thanks to Kris Selden, who explains me that is intented behavior, since two ways bindings work through obj[key], obviously, a string has no such key. And to conclude, there is no binding based on array position.

Upvotes: 3

Related Questions