木偶未捕获TypeError: Object [Object Object]没有ItemView方法'rende
Marionette "Uncaught TypeError: Object [object Object] has no method 'render'", with ItemView
在Bakbone Marionette中,我试图显示一个带有模型数据的IteView。来自其余api的JSON数据很好。问题是,每当我试图在一个区域内显示视图时,它都会显示上述错误。
这是代码:
TestDataModel = Backbone.Model.extend({
url: function(){
return '/test.php?api=getTestData
}
});
TestDataView = Backbone.Marionette.ItemView.extend({
template: Handlebars.compile($('#testing-template').html()),
initialize: function(){
_.bindAll(this);
// I want to bind render when the model changes
this.model.on('change', this.render, this);
this.model.fetch();
}
});
<script id='testing-template' type='text/x-handlebars-template'>
Testing template: {{test_token1}} {{test_token2}}
</script>
// this the main function that render the data on a main base page region.
onRender: function(){
var testModel = new TestDataModel.Model();
var testView = new TestDataView({
model:testModel
});
this.test_region.show(testView);
}
使用onShow代替onRender。当onRender被调用
不要绑定到模型上,尝试使用listenTo约定:
TestDataView = Backbone.Marionette.ItemView.extend({
template: Handlebars.compile($('#testing-template').html()),
initialize: function () {
this.listenTo(this.model, 'change', this.render);
this.model.fetch();
}
});
就像我上面说的,如果这仍然不起作用,你要么错过了什么,要么你需要提供自己的渲染。
不要从视图初始化器中调用fetch。
TestDataModel = Backbone.Model.extend({
url: function(){
return '/test.php?api=getTestData
}
});
TestDataView = Backbone.Marionette.ItemView.extend({
template: Handlebars.compile($('#testing-template').html()),
initialize: function(){
_.bindAll(this);
this.model.on('change', this.render, this);
}
});
<script id='testing-template' type='text/x-handlebars-template'>
Testing template: {{test_token1}} {{test_token2}}
</script>
// this the main function that render the data on a main base page region.
onRender: function(){
var self = this;
var testModel = new TestDataModel.Model();
var testView = new TestDataView({
model:testModel
});
this.testModel.fetch().done(function(){
self.test_region.show(testView);
});
}
相关文章:
- 函数未在Object.keys或Object.getOwnPropertyNames下列出,但可以调用
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- 有没有一种方法可以列出Ember.Object的所有绑定
- 如何取消object.prototypes javascript的一个函数
- 为什么是文档.旧版应用程序中的DOM-object.properties为null
- 将*.js文件的内容放入Object中
- Object.prototype using 'this'
- 使用Object.create()的角度服务继承
- 如何使用object.assign()从其他对象引用基本对象属性
- 循环的数组推入在Object容器中具有不同的值
- reducers在redux中得到Function not Object,what'it’他错了
- JSON.stringify和Object.keys在同一个对象上产生不同的结果
- 在使用object.create创建的对象中使用super
- Join架构验证:Join.object定义数组中的有效键
- jquery打印[object XMLDocument]而不是文件内容
- ExtJS 4 Object.prototype fail
- JavaScript-从对象数组中输出随机OBJECT
- 为什么“{}+1”在Chrome和Firefox中排名第一,而字符串'[object object]1'
- 什么是“;原型;通过JavaScript中的Object Literal Notation创建的对象的链接
- 木偶未捕获TypeError: Object [Object Object]没有ItemView方法'rende