这是解决这个问题的js小提琴:http: //jsfiddle.net/3W47s/9/
这是代码:
<script type="text/x-handlebars">
{{view TitleSelect
contentBinding="App.titlesController"
selectionBinding="App.titlesController.currentTitle"}}
<p>Selected: {{App.titlesController.currentTitle.name}}
(ID: {{App.titlesController.currentTitle.id}})</p>
//---------------------------------
TitleSelect = Ember.Select.extend({
multiple: true,
optionLabelPath: "content.name",
optionValuePath: "content.id"
});
window.App = Ember.Application.create({
ready: function(){
console.info("Hello jsfiddle!:");
var itemArray = [{name: 'Item 1', id: 1}, {name: 'Item 2', id: 2}];
App.titlesController.set('content', itemArray);
}
});
App.titlesController = Ember.ArrayController.create({
currentTitle: null,
testProperty: function(){
console.info("CurrentTitle changed!");
}.property("currentTitle")
});
为什么绑定到 App.titlesController.currentTitle.name 和 App.titlesController.currentTitle.name 的值没有在视图中更新?为什么选择更改时不执行'testProperty'中的打印语句?
这与这个 jsfiddle 非常相似,只是它是多选而不是单选:http: //jsfiddle.net/zgLCr/64/