在模板中,我遍历所有Users
. 从每个User
我想将一个按钮连接到(singluar)xyz
中的一个功能。UserController
我必须如何使用{{action}}
才能做到这一点?现在我所有的尝试都以UsersController
.
索引.html
<script type="text/x-handlebars" data-template-name="users">
<table>
{{#each model}}
<tr>
<td>{{lastName}}</td>
<td><button {{action "xyz" this}}>Xyz</button></td>
</tr>
{{/each}}
</table>
</script>
应用程序.js
App = Ember.Application.create();
App.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
})
App.Router.map(function() {
this.resource('about');
this.resource('users', function() {
this.resource('user', { path: ':user_id' })
})
});
App.UsersRoute = Ember.Route.extend({
model: function() {
return App.User.find();
}
});
App.UserController = Ember.ObjectController.extend({
xyz: function() {
console.log('Bingo!')
}
})
App.User = DS.Model.extend({
lastName: DS.attr('string'),
})
App.User.FIXTURES = [{
id: 1,
lastName: "Clinton"
}, {
id: 2,
lastName: "Obama"
}]