我在你的提琴添加了其他按鈕:
<div><button onclick="App.someObject.set('letterSelection', App.someOptions.objectAt(0));">real a</button></div>
http://jsfiddle.net/Sly7/BYjk6/#base
我認爲你必須使用相同的對象,但不是副本。所以在你的情況下,你必須從綁定到Ember.Select的content屬性的數組中取出對象。
編輯:jsfiddle使用#each和{{action}}。我認爲它會清理模板和代碼。
http://jsfiddle.net/Sly7/sCr8T/
<script type="text/x-handlebars">
{{view Ember.Select
contentBinding="App.someOptions"
selectionBinding="App.someObject.letterSelection"
optionLabelPath="content.val"
optionValuePath="content.id"
}}
{{App.someObject.letterSelection.val}}
{{#each option in App.someOptions}}
<div>
<button {{action "updateSelection" target="App.someObject" context="option"}}>{{option.val}}</button>
</div>
{{/each}}
</script>
的JavaScript:
window.App = Ember.Application.create();
App.someObject= Ember.Object.create({
title: "Some Title",
letterSelection: null,
updateSelection: function(event){
var newSelection = event.context;
this.set('letterSelection', newSelection);
}
});
App.someOptions = [
{'id':'id_a','val':'a'},
{'id':'id_b','val':'b'},
{'id':'id_c','val':'c'},
{'id':'id_d','val':'d'}
];
這是偉大的,謝謝你 – valan 2012-07-18 23:04:53
不客氣:)。順便說一句,通過閱讀你的小提琴,我看到你的燼版看起來很古老。我可以跟蹤更改,我建議你使用主控,或者至少最新的穩定版本0.9.8.1 – 2012-07-18 23:08:40
哦,一定是因爲我GOOGLE了燼和jsfiddle並使用了一個模板,我用實際更高版本dev – valan 2012-07-18 23:13:33