好吧,這裏有一個方法來獲得所選擇的價值,讓我們把東西放在哪裏,他們應該去,OK,首先,讓我們創建一個控制器,它會來裝飾你的反應記錄,你混的名字,你使用後,所以,我會用這個名字,這裏是控制器:
App.PostController = Ember.ObjectController.extend({
selectedChanged: function() {
//here, you have access to the selected value with this:
// this.get('selected')
//And also, this controller represents you object rendered on the screen,
//so, you can change it here if you want like this:
//this.set('whataverPropertyYouWantToChange', 'newValue');
//then you can save this record(send the request to the server) by just doing this:
//this.save(); this will make a request to the server
}.observes('selected')
});
然後,才能使用該控制器,更改您將渲染記錄的循環,更改爲:
{{#each model itemController="post"}}
<tr>
<td>{{author}}</td>
<td>{{book}}</td>
<td>
{{view Ember.Select
contentBinding= 'App.names.content'
selectionBinding='selected'}}
</td>
</tr>
{{/each}}
只是要小心,在PostController中,即使'selected'屬性具有空值,也會觸發觀察者,您需要驗證它是否爲空。
我試過這種方法,但它不工作。例如,我從控制器提醒'this.get(「selected」)',但它什麼都不做。事實上,我認爲在我選擇下拉框時它甚至不會被觸發。 ://jsbin.com/OcAyoYo/107/edit – Anthony
你一定是做錯了,我試着在你的小提琴 – fanta
你沒有做我說的,你沒有創建PostController,你仍然在使用PostsController ,如果你檢查'each'循環,我指定itemController =「post」 – fanta