0
在模板中,我循環遍歷所有Users
。從每個User
我想連接一個按鈕到UserController
(singluar)中的xyz
函數。我如何使用{{action}}
才能做到這一點?現在我所有的嘗試都以UsersController
結束。如何將按鈕連接到其他控制器
的index.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>
app.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"
}]