My model is
var Storage = Backbone.Model.extend({
defaults: {
q_category_id : 2,
dimension: []
}
});
I have a model instance named storageInfo filled with
{
"q_category_id":2,
"dimension":[
{"q_id":1,"q_text":"...","data_type":"1","meta":"15","answer":"152"},
{"q_id":2,"q_text":"...","data_type":"1","meta":"30","answer":"302"},
{"q_id":3,"q_text":"...","data_type":"1","meta":"60","answer":"602"}
]
}
but before sending to the server I want the model to be like this:
{
"q_category_id":2,
"dimension":[
{"q_id":1,"answer":"152"},
{"q_id":2,"answer":"302"},
{"q_id":3,"answer":"602"}
]
}
How can I remove attributes like q_text, datatype and meta from the dimension array of my model?
defaults, the references are copied into new models as needed rather than cloned so yourdimensionarray is subject to surprising reference sharing.defaults: function() { return { ... } }is a better approach in such cases.