我是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
更新了網址 –