I have a JSON which is wrapped with Backbone.Collection like so -
var data = {
"name": "File 1",
"id": "Node100",
"size": "large",
"children": [
{
"name": "File 1-1",
"id": "9da",
"children": [
{
"name": "File 1-1-1",
"id": "30a",
"children": [],
"type": "file_suspected",
"link": {
"id": "9d3",
"type": "started_default"
}
}
],
"type": "file_suspected",
"link": {
"id": "f70",
"type": "started_default"
}
}
],
"type": "file_default",
"link": {
"id": "970",
"type": ""
}
}
var collection = new Backbone.Collection(data);
collection.on('change', function(obj) {
console.log("collection changed. ");
});
collection.at(0).set('type', 'hello');
//When nested data change, collections 'change' event does not get triggered.
collection.at(0).get('children')[0]['type'] = "hello_1";
When any of the nested data is updated, the 'change' event on the collection does not trigger. Typically, you would expect a flat structure with objects in an array. But given this nested structure, how should I go about setting up this collection. The end goal is to have a collection which is aware of updates (add, edit, remove).