SupermodelBackbonejs 的数据模型层

联合创作 · 2023-09-22 13:21

Supermodel 是 Backbonejs 的数据模型层。


示例代码:



Post.has().many('comments', {
collection: Comments,
inverse: 'post'
});

Comment.has().one('post', {
model: Post,
inverse: 'comments'
});

var post = Post.create({
id: 1,
comments: [{id: 2}, {id: 3}, {id: 4}]
});

post.comments().length; // 3
var comment = Comment.create({id: 5, post_id: 1});
post.comments().length; // 4
comment.post() === post; // true :D
浏览 15
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报