我有一个主干模型,如下所示
define([], function(){
var instaceUrl;
var PatientModel = Backbone.Model.extend({
url: function() {
return instanceUrl;
},
initialize: function(options) {
instanceUrl = options.instanceUrl;
},
defaults: {
"person": "",
"identifiers":""
}
});
console.log('Patient model');
return PatientModel;
});
当我尝试保存患者模型patientModel.save
时,请求有效负载中添加了一个额外的instanceUrl
属性
var patientModel = new PatientModel({instanceUrl: '/patient'});
...
...
patientModel.set("identifiers", identifiers);
patientModel.set("person", uuid);
patientDetails = patientModel.toJSON();
patientModel.save(patientDetails, {
beforeSend : sendAuthentication,
success : function(model, response, options) {
uuid = response.uuid;
},
error : function() {
alert('failed');
}
});
模型发送以下有效载荷
{
"instanceUrl": "/patient", // why is it added ?
"person": "c014068c-824d-4346-84f0-895eb3ec6af7",
"identifiers": [
{
"preferred": true,
"location": "f15bc055-765a-4996-a207-ec4945972f33",
"identifier": "saks9639",
"identifierType": "866aedab-8a37-4b15-95d3-2b775fc0caac"
}
]
}
REST API 调用成功所需的有效负载是
{
"person": "c014068c-824d-4346-84f0-895eb3ec6af7",
"identifiers": [
{
"preferred": true,
"location": "f15bc055-765a-4996-a207-ec4945972f33",
"identifier": "saks9639",
"identifierType": "866aedab-8a37-4b15-95d3-2b775fc0caac"
}
]
}
如何避免patientModel
考虑instanceUrl
作为模型属性?