Backbone.js 主干supermodel.js--从本地存储获取后,模型的关联丢失
我有两个骨干超级模特Backbone.js 主干supermodel.js--从本地存储获取后,模型的关联丢失,backbone.js,model,relationship,Backbone.js,Model,Relationship,我有两个骨干超级模特Info和Content,并且以如下方式将1对1关联起来: Info.has().one('content', { model: Content, inverse: 'info' }); Content.has().one('info', { model: Info, inverse: 'content' }); 并将这两个模型的实例保存到不同的本地存储中: Info.all().localStorage = new
Info
和Content
,并且以如下方式将1对1
关联起来:
Info.has().one('content', {
model: Content,
inverse: 'info'
});
Content.has().one('info', {
model: Info,
inverse: 'content'
});
并将这两个模型的实例保存到不同的本地存储中:
Info.all().localStorage = new Backbone.LocalStorage('info'); // all() returns the collection.
Content.all().localStorage = new Backbone.LocalStorage("content");
// instances of Info Model. 'id' would be generated when calling initialize()
var info1 = Info.create();
var info2 = Info.create();
var content1 = Content.create({
info_id: info1.get('id')
});
var content2 = Content.create({
info_id: info2.get('id')
});
// save to localStorage
info1.save();
info2.save();
content1.save();
content2.save();
取出后,所有关联都会丢失:
Info.all().fetch();
Content.all().fetch();
Info.all().at(0).content(); // undefined.
以前有人见过这个吗?你是怎么做到的
此外,,
保证
关联属性是使用getter函数检索的。这个
允许通过集合进行延迟加载等优化。其他
将来也可能延迟加载关联
这是否意味着我可以通过在(0)加载与Info.all()关联的内容
模型
Info.all().at(0).content();
即使尚未获取内容模型的实例?(似乎不起作用)
如何实现这种延迟加载