Im trying to fetch the data/api using a node/express route with data stored in mongo/mongoose and show it inside Backbone Marionette...
The route im using is this:
enter code here`app.get('/cats', function(req, res){
Cat.find({}, function (err, docs) {
res.send(docs);
});
});
2) When I go to localhost:3000/cats, I get the json working as:
[
{
"__v": 0,
"_id": "51318ce9a7ff43f808000003",
"catname": "Jonas"
},
{
"catname": "Justin",
"_id": "51416268a8225e7413000001",
"__v": 0
},
{
"catname": "Bobby",
"_id": "51416268a8225e7413000001",
"__v": 0
}
]
3) Now how can I have the collection/model/itemview/etc use this json data from my db?
I usually get this far:
MyCat = Backbone.Model.extend({});
MyCats = Backbone.Collection.extend({
model: MyCat,
url: '/cats'
});
CatView = Backbone.Marionette.ItemView.extend({
template: "#cats-template",
tagName: 'li',
className: 'cat'
});
AngryCatsView = Backbone.Marionette.CompositeView.extend({
tagName: "ul",
id: "cats",
template: "#cats-template",
itemView: CatView,
appendHtml: function(collectionView, itemView){
collectionView.$("ul").append(itemView.el);
}
});
But then im not sure which type of initializer to use. I've seen examples with hardcoded json, but none from a db.