我正在尝试运行此代码,但出现此错误:Uncaught TypeError: string is not a function
在哪里写:var html = template(context);
有人知道原因吗?
看法
define(["jQuery", "underscore", "Backbone", "Handlebars","models/person" ,"text!templates/userlistview.html"],
function($, _, Backbone, Handlebars,Person, template) {
var UserListView = Backbone.View.extend({
template: Handlebars.compile(template),
render: function() {
var context = JSON.parse(JSON.stringify(this.model));
console.log(context);
var html = template(context);
$(this.el).html(html);
return this;
}
});
return UserListView;
});
路由器
define(["jQuery", "underscore", "Backbone", "collections/usercollection", "models/person", "views/userlistview"],
function($, _, Backbone, Usercollection, Person, UserListView) {
var AppRouter = Backbone.Router.extend({
routes: {
"": "list",
},
list: function() {
this.utenti= new Person({name:"stefano",cognome:"magli"});
this.page= new UserListView({model:this.utenti});
this.page.render();
}
});
return AppRouter;
});