本文介绍了如何处理已创建但未使用的额外记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户进入路由时,这是在模型钩子中createRecord的常见模式。
it's a common pattern to createRecord in the model hook when user enters the route.
有时,这些记录仍然未使用,并且在某些情况下弹出,即在peekAll查询中,尽管这是不需要的。如何处理他们?
Sometimes those records remain unused, and they pops up in certain conditions, i.e. in peekAll query, although that is unwanted. How do deal with them?
推荐答案
如果创建是路由的主要责任,您可以在停用
路线事件,例如:
If creation is the main responsibility for the route, you could destroy model on deactivate
route event, for example:
//route
model: function() {
return this.store.createRecord('modelName');
},
cleanModel: function() {
var model = this.modelFor( this.routeName );
if (model.get('isNew')) {
model.destroyRecord();
}
}.on('deactivate')
事件。当路由型号发生变化时,不会执行。
Deactivate event is triggered when the router completely exits this route. It is not executed when the model for the route changes.
这篇关于如何处理已创建但未使用的额外记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!