我在布局视图中加载预编译的把手模板。我定义了区域,但是,我得到了错误:
Uncaught Error: An "el" #questions-section must exist in DOM
(当然该节点存在于模板中)。
这是因为我使用的是预编译模板吗? 代码:
q.boxView = Marionette.LayoutView.extend({
tagName : 'li',
className : "sortable_boxes_original",
template: Handlebars.templates["repoboxview"],
initialize : function(){
this.createQuestionsCollection();
this.createResponsesModel();
this.listenTo(this.model.get("response"), 'change', this.triggerChanged);
},
regions: {
questions: "#questions-section"
},
onBeforeRender: function(){
var that = this;
this.getRegion("questions").show(new q.questionsListView({collection: this.model.get("questions"), model: this.model}));
}
});
答案 0 :(得分:2)
它正在发生,因为在该区域实际上是DOM的一部分之前,您正试图在该区域放置一些东西。来自documentation:
如果View可以访问区域定义中指定的元素,则区域将只能填充自身。也就是说,如果您的视图尚未呈现,您的区域可能无法找到您指定要管理的元素。在这种情况下,使用该区域将不会导致DOM的更改。
因此,请尝试onBeforeShow()
。
onBeforeRender()
答案 1 :(得分:2)
除了凯文的回答之外,更适合回调以显示儿童观看地区的是onBeforeShow()