Why does this trigger the "change" event on the Backbone Collection?
data.json file:
[
{
"id": 1,
"name": "Alex",
"comments": [
{
"id":5
}
]
},
{
"id": 2,
"name": "Tom",
"comments": []
}
]
data for model:
data = [
{
id: 1,
name: "Alex",
comments: [
{
id:5
}
]
},
{
id: 2,
name: "Tom",
comments: []
}
]
var Model = Backbone.Model.extend({
initialize: function () {
console.log('init model');
}
});
var View = Backbone.View.extend({
initialize: function () {
console.log('init view');
}
});
var Collection = Backbone.Collection.extend({
model: Model,
url: "data.json",
initialize: function () {
console.log('init collection');
}
});
Add data to model:
var collection = new Collection(data);
collection.on('change', function () {
console.log('change');
})
Fetch:
collection.fetch({
update: true,
merge: true
})
After fetch we see 'change' in the console.
Please, help me. I must use this event, but I don't want trigger event on "comments", if the data has not changed.