I have a model with a name attribute that has a bind function to be called when the attribute is changed:
var Workitem = Backbone.Model.extend({
initialize: function(){
this.bind('change:name', function() {
alert('name');
}
});
},
defaults: {
name: 'Name'
}
});
If I fetch a single model, this works, and the change event is triggered when I set the attribute and when I fetch the data.
But then I've created a collection and I want the event to be triggered for each fetched model into the collection during the fetch method:
var WorkitemList = Backbone.Collection.extend({
model: Workitem,
});
var workitemsList = new WorkitemList();
workitemsList.fetch();
Is this possible?
Fetch triggers 'reset' event on the collection when import is done. listen on it, fire / mess with models then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With