2012-04-04 63 views

回答

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();​ 
+0

謝謝,但我需要更新此對象......和默認實現RESTAdapter做這樣的: 'this.sideload(存儲,類型,'json,root);' 'store.didCreateRecord(model,json [root]);' 並且它會爲子元素創建奇怪的POST和GET請求。換句話說 - 我需要更新所創建元素的ID – 2012-04-04 12:10:05