好的,这是获取选定值的一种方法,让我们把东西放在应该去的地方,好的,首先,让我们创建一个控制器来装饰你的响应记录,你混合名字,你正在使用 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' 属性具有空值,观察者也会被触发,您需要验证它是否不为空。