Backbone.js "model" query
Posted
by
Novice coder
on Stack Overflow
See other posts from Stack Overflow
or by Novice coder
Published on 2013-06-26T04:16:47Z
Indexed on
2013/06/26
4:21 UTC
Read the original article
Hit count: 182
I'm a learning coder trying to understand this code from a sample MVC framework.
The below code is from a "model" file. I've done research on Backbone.js, but I'm still confused as to exactly how this code pull information from the app's database. For example, how are base_url
, Model.prototype
, and Collection.prototype
being used to retrieve information from the backend? Any help would be greatly appreciated.
exports.definition = {
config : {
"defaults": {
"title": "-",
"description": "-"
},
"adapter": {
"type": "rest",
"collection_name": "schools",
"base_url" : "/schools/",
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// Extend, override or implement Backbone.Model
urlRoot: '/school/',
name:'school',
parse: function(response, options) {
response.id = response._id;
return response;
},
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// Extend, override or implement Backbone.Collection
urlRoot: '/schools/',
name: 'schools',
});
return Collection;
}
}
© Stack Overflow or respective owner