Backbone.Marionette ItemView控件嵌套要么没有渲染或渲染"空白"视图/模板 [英] Backbone.Marionette nested ItemView either not rendering or rendering "blank" view/template

查看:504
本文介绍了Backbone.Marionette ItemView控件嵌套要么没有渲染或渲染"空白"视图/模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在导航到一个特定的URL,控制方法被触发,它加载的ItemView控件到我的应用程序的地区之一。这本身ItemView控件(父)将包含子ItemViews了一把,使他们都当它呈现自己。这里的家长ItemView控件:

On navigating to a specific URL, a controller method is fired, which loads an ItemView into one of my application's regions. This ItemView itself (the parent) will contain a handful of child ItemViews, rendering them all when it's rendered itself. Here's the parent ItemView:

return Backbone.Marionette.ItemView.extend({
    template: Handlebars.compile(template),
    ui: {
        textInput01: "#text-input-01"
    },
    events: {
        // no events yet
    },
    initialize: function() {
        // no init yet
    },
    onRender: function() {
        this.appRoutefinderTextinputItemView = new AppRoutefinderTextinputItemView({parentView: this});

        $(this.ui.textInput01).html(this.appRoutefinderTextinputItemView.render());
    }
});

和这里的当前唯一的ItemView控件:

And here's the current sole ItemView:

return Backbone.Marionette.ItemView.extend({
    template: Handlebars.compile(template),
    events: {
        // no events yet
    },
    initialize: function() {
        // no init yet
    },
    onRender: function() {
        // no onRender yet
    }
});

有关某种原因,我无法捉摸,但无论是初始化和子的OnRender 方法烧制,并所有必要的数据似乎是present,孩子或者不被呈现或以空白的方式被呈现,导致不变父视图

For some reason I cannot fathom, though both the initialize and onRender methods on the child are firing, and all necessary data seems to be present, the child is either not being rendered or is being rendered in a "blank" manner, resulting in an unchanged parent view.

据我了解,我不应该需要调用渲染()的孩子,因为它实例/引用一个ItemView控件时的暗示?甚至当我把渲染()电话,同样的结果来。

As far as I understand, I shouldn't need to call render() on the child, as it's implied when instantiating/referencing an ItemView? Even when I drop the render() call, the same result is come to.

我必须假设有一些关于从我只是缺少其他ItemViews内渲染ItemViews,而是通过文档淘似乎并没有帮助。

I've got to assume there's something about rendering ItemViews from within other ItemViews that I'm just missing, but scouring through the docs didn't seem to help.

一个次要的问题是:我该实例以适当方式对孩子的看法,还是有更好的方式来做到这一点。

A secondary question would be: am I instantiating the child views in the proper manner, or is there a better way to do so?

*编辑 - 所以一些试验后,出现了接受的解决方案是简单地让家长图的布局,这是一个扩展ItemView控件。这并不工作。不过,我仍然在想为什么一个ItemView控件中的一个ItemView控件不起作用。我是打算手写渲染()方法的整合ItemView控件,被我保持这种方式?

*EDIT - So after some experimenting, it appears that the "accepted" solution is simply to make the parent view a Layout, which is an extended ItemView. This does work. However, I'm still left wondering why an ItemView within an ItemView doesn't work. Am I intended to integrate a hand-written render() method on the ItemView, were I to keep it that way?

推荐答案

与你原来的code的问题是这一行:

The problem with your original code is this line:

$(this.ui.textInput01)的.html(this.appRoutefinderTextinputItemView.render());

骨干视图的渲染方法不返回呈现的HTML。此方法执行渲染和更新视图。这个方法的返回值是视图本身。木偶不改变这种行为。

The render method of a backbone view does not returned the rendered HTML. This method does the rendering and updates the el of the view. The return value of this method is the view itself. Marionette does not change this behavior.

您需要更改code与视图的来填充textInput01。还要注意的是 this.ui.textInput01 已经是一个jQuery选择的对象,所以你不需要换一遍。

You need to change the code to populate the textInput01 with the view's el. Also note that the this.ui.textInput01 is already a jQuery selected object so you don't need to wrap that again.


this.appRoutefinderTextinputItemView.render();
this.ui.textInput01.html(this.appRoutefinderTextinputItemView.el);

这篇关于Backbone.Marionette ItemView控件嵌套要么没有渲染或渲染"空白"视图/模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆