我是backbone.js和handlebars的新手,我有一个问题让我的模板渲染出数据。backbone.js,handlebars错误:this._input.match不是函数
这里是tagfeed.js模块我的采集和模型数据:
// Create a new module.
var Tagfeed = app.module();
// Default model.
Tagfeed.Model = Backbone.Model.extend({
defaults : {
name : '',
image : ''
}
});
// Default collection.
Tagfeed.Collection = Backbone.Collection.extend({
model : Tagfeed.Model,
url : Api_get('api/call')
});
Tagfeed.TagView = Backbone.LayoutView.extend({
template: "tagfeed/feed",
initialize: function() {
this.model.bind("change", this.render, this);
},
render: function(template, context) {
return Handlebars.compile(template)(context);
}
});
然后在我的路由器,我有:
define([
// Application.
"app",
// Attach some modules
"modules/tagfeed"
],
function(app, Tagfeed) {
// Defining the application router, you can attach sub routers here.
var Router = Backbone.Router.extend({
routes: {
"index.html": "index"
},
index: function() {
var collection = new Tagfeed.Collection();
app.useLayout('main', {
views: {
".feed": new Tagfeed.TagView({
collection: collection,
model: Tagfeed.Model,
render: function(template, context) {
return Handlebars.compile(template)(context);
}
})
}
});
}
});
return Router;
});
这个成功使得该API的调用,进行呼叫获取我的主模板,并调用获取Feed模板的HTML。如果我没有包含该渲染(模板,上下文)功能,那么它会在页面上呈现为我在包含{{name}}的Feed模板中包含的直线HTML。但其包含的时候,我得到的错误
TypeError: this._input.match is not a function
[Break On This Error]
match = this._input.match(this.rules[rules[i]]);
,如果我检查该得到传递到appLayout意见渲染功能feed
变量,我看到template
var是一个功能,并且context
VAR是未定义,那么它会抛出该错误。
任何想法我做错了什么?我知道我在这里至少有一个问题,可能更多。
链接样板例子是404 :( – andyzinsser
更新了网址 –