var model = Backbone.Model.extend({
parse : function (response) {
// you can modify model
response.author || (response.author = 'Anonymous');
return response;
},
getArticleTitle : function () {
return this.get('author') + ' - ' + this.get('title');
}
});
var collection = Backbone.Collection.extend({
url: '/rest/article',
model: model
});
// you can access model methods
collection.at(0).getArticleTitle();
backbone why using model in collection
-
01-07-2022 - |
Question
why use model inside collection, can someone explain me?
Example:
var model = Backbone.Model.extend({
url: '/rest/article/'
});
var collection = Backbone.Collection.extend({
url: '/rest/article',
model: model
});
Solution
OTHER TIPS
So whenever you add an item to the collection it can be instantiated as that kind of model.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow