【问题标题】:CompositeView - An event which will be fired post rendering of all the child recordsCompositeView - 将在渲染所有子记录后触发的事件
【发布时间】:2016-12-08 22:37:49
【问题描述】:

我正在尝试使用 CompositeView 呈现记录列表,但我无法识别将在呈现所有子记录后触发的事件。

我浏览了文档,发现以下方法尚未奏效 -

  1. onRenderCollection - 在模型集合被渲染之后
  2. onRender - 渲染完所有内容后
  3. render:collection - 试了试一下

下面是当前代码sn -p -

        View.childItem = Backbone.Marionette.ItemView.extend({
            template: childTpl,
            tagName: 'tr'
        });


        View.parentPane = Backbone.Marionette.CompositeView.extend({
            template: parentTpl,
            childView: View.childItem,
            childViewContainer: "#childList",
            events: {

            },
            onAfterRender: function (ev) {
                $('tbody').css('height', '210px')); // trying to control the height dynamically..
            },

        });

【问题讨论】:

  • childView: View.childTpl 应该不是childView: View.childItem
  • 谢谢,已更正。

标签: javascript backbone.js marionette composite-view


【解决方案1】:

我想你正在寻找onRender

此外,在渲染复合视图后,onRender 方法将被调用。您可以在您的视图中实现此功能以提供 用于在渲染后处理视图的 el 的自定义代码。

View.parentPane = Backbone.Marionette.CompositeView.extend({
  template: parentTpl,
  childView: View.childTpl,
  childViewContainer: "#childList",
  onRender: function () {
    $('tbody').css('height', '210px')); // trying to control the height dynamically..
  }
});

【讨论】:

  • 奇怪的是,我的 onRender 在渲染事件开始时触发,而不是在它之后触发,因此希望 onAfterRender 不起作用。
【解决方案2】:

试试render:collection/onRenderCollection。请参阅 Marionette 文档中的 "render" event

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2012-03-19
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    相关资源
    最近更新 更多