Ember.js 未从集合中删除余烬中已删除的记录
我正在构建一个简单的CRUD应用程序。我有一个从服务器获取的记录列表,单击第一个,我就在该记录的Ember.js 未从集合中删除余烬中已删除的记录,ember.js,Ember.js,我正在构建一个简单的CRUD应用程序。我有一个从服务器获取的记录列表,单击第一个,我就在该记录的显示页面上,有一个删除按钮,该按钮与控制器上的此操作相关联: destroy: function() { this.content.deleteRecord() this.store.commit() this.transitionTo('usersIndex') } 我知道记录已被删除,我可以在服务器上看到它已被删除。AJAX请求成功。但是,该记录仍然显示在索引页上。如果我从服务器进行
显示
页面上,有一个删除
按钮,该按钮与控制器上的此操作相关联:
destroy: function() {
this.content.deleteRecord()
this.store.commit()
this.transitionTo('usersIndex')
}
我知道记录已被删除,我可以在服务器上看到它已被删除。AJAX请求成功。但是,该记录仍然显示在索引页上。如果我从服务器进行硬刷新,它现在就消失了
我的usersIndex
路由器如下:
App.UsersIndexRoute = Ember.Route.extend({
model: function(params) {
return App.Users.find();
},
setupController: function(controller, model) {
controller.set('content', model);
}
});
我在项目中应用的解决方案是增强usersIndex以过滤掉任何isDeleted记录,例如 在模板中,类似于:
{{#unless user.isDeleted}}
{{render 'user' user}}
{{/unless}}
还可以利用后置模型挂钩测试isDeleted,例如:
afterModel: function(model){
if ((!model.get('users').isAny('isDeleted',false)) || model.get('users.length') === 0){
this.send('exitUserIndex');
}
}
调用deleteRecord后,必须将其保存为余烬数据
destroy: function() {
this.content.deleteRecord()
this.content.get('isDeleted');
this.content.save()
this.store.commit()
this.transitionTo('usersIndex')
}
或者,您也可以起诉destroyRecord,该记录从后端和余烬数据中删除了thh记录
destroy: function() {
this.content.destroyRecord()
this.transitionTo('usersIndex')
}
希望这有帮助 你知道为什么吗?我也有类似的问题,有人找到合适的工作吗?(我有同样的问题)这是一个新问题吗?更新它以删除我的问题。