在 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);
}