I am a newbie to Backbone and need help to get and set the models from a nested Json Structure using Backbone
I have a simple model and collection below
Model:
var PmaslDataModel = Backbone.Model.extend({ });
Collection:
app.PmaslDataCollection = Backbone.Collection.extend({
url APPLICATION_URL+'aslview/getformatedDataRows',
model : PmaslDataModel
});
Initialize the collection
var pmaslDataCollection = new app.PmaslDataCollection();
Fetching the above collection returns the data in the Json Format below
{
"id" : "1",
"rowid" : "1",
"group" : "10__",
"datarows": [
{
"id": "sspvk_code",
"default_display": "1",
"order": "1",
},
{
"id": "sspvk_code2",
"default_display": "0",
"order": "0",
},
{
"id": "sspvk_code3",
"default_display": "1",
"order": "0",
}
]
},
{
"id" : "2",
"rowid" : "2",
"group" : "11__",
"datarows": [
{
"id": "sspvk_code",
"default_display": "1",
"order": "1",
},
{
"id": "sspvk_code2",
"default_display": "0",
"order": "0",
},
{
"id": "sspvk_code3",
"default_display": "1",
"order": "0",
}
]
}
I have to use the above structure to populate the values in a table where we have the row ids and the column values in the row appears in the datarows attributes
I have 2 Questions
- How can I set the "default_display" value to 0 for all the datarows with id=sspvk_code ?
- If I have a particular row id how can I fetch the datarows for that row,pass it to a underscore template and populate the template (that is ,in the template I need to access it with model.get('attributename value')