【发布时间】:2013-12-05 11:12:22
【问题描述】:
Backbone-Relational 中的模型缓存非常好,但是要安全地加载简单模型需要相当多的代码。例如
// Try and find a model in the Cache
this.model = MyModel.find({id:id});
if(this.model){
// Model loaded from cache, do something.
this.doSomething();
}else{
// Load model then do something on success.
var self = this;
this.model = new MyModel({id:id});
this.model.fetch({
success: function(){
self.doSomething();
}
});
}
我猜你可以写一个实用函数,但是有更好的方法吗?好像太啰嗦了。
【问题讨论】:
标签: javascript backbone.js backbone-relational