我试着使用与存储在蒙戈/猫鼬数据的节点/快递途径获取数据/ API,并显示它骨干木偶里面......填充骨干木偶意见与猫鼬数据使用快速通道
路线即时通讯使用的是这样的:
enter code here`app.get('/cats', function(req, res){
Cat.find({}, function (err, docs) {
res.send(docs);
});
});
2)当我去为localhost:3000 /猫,我得到的JSON作为工作:
[
{
"__v": 0,
"_id": "51318ce9a7ff43f808000003",
"catname": "Jonas"
},
{
"catname": "Justin",
"_id": "51416268a8225e7413000001",
"__v": 0
},
{
"catname": "Bobby",
"_id": "51416268a8225e7413000001",
"__v": 0
}
]
3)现在,我怎么能有收集/模型/ ItemView控件/等c从我的数据库使用这个json数据?
我通常到了这一步:
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);
}
});
但随后林不知道初始化的类型要使用的。 我见过硬编码JSON的例子,但没有一个从数据库。
问题是此... 变种thecats = myCats(); thecats.fetch(); 希望它可以帮助别人... – 1ManStartup 2013-04-01 19:47:21