Ember.js 余烬毁灭记录失败
我有一个ember/ember cli应用程序,正在努力删除记录。以下是操作定义:Ember.js 余烬毁灭记录失败,ember.js,ember-cli,Ember.js,Ember Cli,我有一个ember/ember cli应用程序,正在努力删除记录。以下是操作定义: export default Ember.ObjectController.extend({ actions: { remove: function() { var model = this.get('model'); model.destroyRecord(); this.transitionToRoute('foo'); } } }); 通过使用控
export default Ember.ObjectController.extend({
actions: {
remove: function() {
var model = this.get('model');
model.destroyRecord();
this.transitionToRoute('foo');
}
}
});
通过使用控制台日志语句,我可以看到该方法被调用
下面是调用操作的方式:
<div class="panel-body list-group">
{{#each tournament in model}}
{{#link-to 'tournaments.play' tournament class="list-group-item"}}
<span><strong>{{tournament.name}}</strong> <em>{{tournament.eventDate}}</em></span>
<span {{action 'remove' tournament}} class="glyphicon glyphicon-trash pull-right"></span>
{{/link-to}}
{{/each}}
</div>
看来我的行动被叫来了,一些模型出现了。我做错了什么?我如何诊断这个?我所做的似乎和我在指南中看到的一样:您在操作中忘记了参数(除非您想破坏控制器的模型,它是列表,而不是单个比赛。) 返回一个承诺,这样更好
remove: function(tournament) {
var controller = this;
tournament.destroyRecord().then(function() {
controller.transitionToRoute('foo');
}, function(error) {
// todo better error handler, show message to user...
console.error(error);
});
}
我的操作有
{{action'remove'tournament}}
应该是什么?模板没问题,它是控制器中的函数。我已经更新了答案。成功!我稍后会回来接受(仍然处于接受冻结状态)
remove: function(tournament) {
var controller = this;
tournament.destroyRecord().then(function() {
controller.transitionToRoute('foo');
}, function(error) {
// todo better error handler, show message to user...
console.error(error);
});
}