使用 hasMany associacion 持久化新模型实体的任何示例?
问问题
533 次
1 回答
2
这是一个例子,见http://jsfiddle.net/pangratz666/vuT2v/
App.Comment = DS.Model.extend({
text: DS.attr('string')
});
App.Post = DS.Model.extend({
title: DS.attr('string'),
comments: DS.hasMany('App.Comment')
});
var first = App.Comment.createRecord({
id: 'firstComment',
text: 'first comment'
});
var second = App.Comment.createRecord({
id: 'secondComment',
text: 'second comment'
});
var post = App.Post.createRecord({
id: 1,
title: 'post title'
});
var comments = post.get('comments');
comments.addObject(first);
comments.addObject(second);
App.store.commit();
于 2012-04-04T11:04:19.223 回答