好吧,这里有一种方法来获得所选的值,让我们把它们放在应该放的地方,好吧,首先,让我们创建一个控制器,它将装饰你的响应记录,你混合了名称,你正在使用Post,所以,我将使用这个名称,这是控制器:
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”属性具有null值,也会触发观察者,您需要验证它是否为null。