有谁能告诉我为什么这段代码会在var myview = new view();
处抛出“未定义的不是函数”错误?我一直在寻找,我很确定一切都是对的。
router = Backbone.Router.extend({
routes: {
'/': 'project'
},
project: function() {
projects = new models.Projects();
var view = Backbone.View.extend({
el: 'body' ,
render : function() {
$(this.el).empty().append(templates.Project({content : 'this works!' }));
return this;
}
});
console.log(view);
/*
* Output:
* { [Function]
extend: [Function],
augment: [Function],
toString: [Function],
register: [Function],
__super__:
{ bind: [Function],
unbind: [Function],
trigger: [Function],
tagName: 'div',
'$': [Function],
initialize: [Function],
render: [Function],
remove: [Function],
make: [Function],
delegateEvents: [Function],
_configure: [Function],
_ensureElement: [Function],
html: [Function],
toString: [Function],
template: [Function] } }
*/
var myview = new view();
this.send(myview, {collection: projects});
}
});
答案 0 :(得分:0)
尝试
怎么样?new view
而不是
new view();
或者尝试传递一个模型:
new view({});
答案 1 :(得分:0)
设置el:
时需要使用JQueryvar view = Backbone.View.extend({
el: $('body'),
render: function() {
$(this.el).empty().append(templates.Project({content : 'this works!' }));
return this;
}
});
var myview = new view();
查看this answer了解详情。