I have this backbone script, which has a single view and a model acting as a controller, and a collection where data is being fetched from the server url: '/search/:term' .
var Items = Backbone.Collection.extend({
initialize: function(terms){
this.fetch();
}
url: 'search/:term'
});
var Controller = Backbone.Model.extend({
defaults:{
term: ""
},
initialize: function(opts){
this.on('change:term', function(term){
console.log(this.get("term"));
// every time term changes i want to refresh the collection with the new data
// so it will fetch data from url:'search/ + term'
});
could someone help me with this thank you.
}
});
In a backbone context a View acts as a Controller (read controller form mvc). Can you try to do something like this?