【发布时间】:2014-06-16 01:58:25
【问题描述】:
我有一个Em.ArrayController,里面有很多记录。它们都由itemController 控制。
App.ColorsController = Em.ArrayController.extend({
itemController: 'color',
actions: {
discardChanges: function() {
this.get('content').forEach(function(color) { color.rollback(); }
// also tried an arrayComputed property like this:
// deletedRecords: Em.computed.filterBy('content', 'isDeleted', true);
}
}
});
如果我在其中一个模型上调用 deleteRecord()(从 itemController 中的操作,模型将从 ArrayController 的 model 中删除。
App.ColorController = Em.ObjectController.extend({
actions: {
deleteColor: function() {
// does not send a `DELETE` request, only
// changes the state of the record
this.get('content').deleteRecord();
}
}
});
请记住deleteRecord 不会提交网络请求,它只是将对象的状态转换为deleted.uncommitted。
删除后我是否需要手动保留该对象的某种句柄?或者 ArrayController 是否有某种方式可以访问此状态下的项目。
我尝试通过isDeleted 过滤ArrayController 的内容。
【问题讨论】:
标签: ember.js ember-data