我对backbone.js非常基础,我正在尝试向body添加几个元素,因为它使用了这个函数,但我得到的错误是“Uncaught ReferenceError:age is not defined”——我的有什么问题代码?
我得到的错误:
"Uncaught ReferenceError: age is not defined"
HTML(模板):
<script id="person" type="text/template">
<strong><%= name %></strong><sup><%= age %></sup>
</script>
功能:
(function($){
var Model = Backbone.Model.extend({
defaults:{
name:'default name',
age:'default age'
}
});
var Col = Backbone.Collection.extend({
model:Model
});
var PersonView = Backbone.View.extend({
tagName:'li',
template:_.template($('#person').html()),
initialize:function(){
this.render();
},
render:function(){
$('body').append(this.$el.html(this.template(this.model.toJSON())));
}
});
var ncol = new Col({model:[{name:'abc',age:1},{name:'cdf',age:2},{name:'ghi',age:1}]});
var persons = new PersonView({model:ncol});
})(jQuery)
任何人帮助我解决我的问题..?