在 Bakbone Marionette 中,我尝试显示包含模型数据的 IteView。 来自其余 api 的 JSON 数据正常。问题是,每当我尝试在区域内显示 View 时,它都会显示上述错误。
这是代码:
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时区域尚未设置
关于javascript - Marionette "Uncaught TypeError: Object [object Object] has no method ' 渲染'",带有 ItemView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16267162/