我有一个附加到模型的集合。当我单击一个按钮时,我希望能够告诉主干仅将一个属性(包含集合)保存到服务器
m.Survey = m.BaseModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'invites',
relatedModel: 'APP.Models.SurveyInvite',
collectionType: 'APP.Collections.SurveyInvites',
//save invites separately
includeInJSON: false,
reverseRelation: {
key: 'survey',
//We don't want to list the survey when doing toJSON()
includeInJSON: false
}
}],
//need this method
saveInvites: function(){
this.saveOnly('invites');
});
});
我希望它发送到服务器:
发布 /api/surveys/123/
{
invites: [
{<invite1>}, {<invite2>}, {<invitex>}
]
}