Controller:
games : Ember.A(["1", "2", "3"]),
View:
{{#each view.games}}
{{view Ember.TextField valueBinding="this"}}
{{/each}}
当我更改文本字段的值时,它没有同时更改数组?
答案 0 :(得分:3)
<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/
编辑:感谢Kris Selden,他解释了我的意图行为,因为两种方式绑定通过obj [key]工作,显然,字符串没有这样的键。最后,没有基于数组位置的绑定。