我(作为初学者)制作了一个小的主干函数来附加我的链接,为此我使用要分配模型的集合,
但是集合抛出错误..任何人都可以更正我的代码吗?
$(function(){
var Model = new Backbone.Model({
data:[
{name:'Yahoo',href:'http://www.yahoo.com'},
{name:'Gmail',href:'http://www.gmail.com'},
{name:'Bing',href:'http://www.bing.com'}
]
});
var Collection = new Backbone.Collection.extend({
model:Model // is this not correct way to do?
});
var View = Backbone.View.extend({
el:'#container',
events:{
'click button':'render'
},
initialize:function(){
this.collection = new Collection(); //throw the error!
this.template = $('#temp').children();
},
render:function(){
var data = this.collection.get('data');
for(i=0;i<data.length;i++){
var li = this.template.clone().find('a')
.attr('href',data[i].href)
.text(data[i].name).end();
this.$el.find('ul').append(li);
}
}
});
var myLink = new View();
})