【问题标题】:Widgets inside Dojo dgrid OnDemandListDojo dgrid OnDemandList 中的小部件
【发布时间】:2013-07-10 22:38:31
【问题描述】:

我正在尝试做类似于this question 的事情,但使用的是 OnDemandList 而不是 OnDemandGrid。

这是我目前所拥有的

define([
    "dojo/_base/declare",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dijit/_WidgetsInTemplateMixin",
    "dgrid/OnDemandList",
    "widget/CategoryItem",
    "dojo/dom-construct",
    "dojo/text!./templates/category-list.html"
], function(declare, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, OnDemandList, CategoryItem, domConstruct, template) {
    var CatList = declare([OnDemandList]);
    return declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
        templateString: template,
        baseClass: "category-list",

        postCreate: function() {
            this.inherited(arguments);

            // Create OnDemandList, place in div defined in template.
            var cat1 = this.cat1 = new CatList({
                store: this.store,
                renderRow: this.renderItem
            }, this.categoriesLevel0);

        },

        renderItem: function(item) {
            return new CategoryItem({
                title: item.title
            });
        }
    });
});

问题是我的 renderItems 函数需要以某种方式返回一个包含我的自定义小部件的 dom。现在我收到此错误Error on domReady callback: Error: NotFoundError: DOM Exception 8

【问题讨论】:

    标签: dojo dgrid


    【解决方案1】:

    是的,它肯定需要从 renderRow 返回一个 dom 节点。假设您使用 _WidgetBase 作为 CategoryItem 它应该像这样工作:

    renderItem: function(item) {
        var category = new CategoryItem({
            title: item.title
        });
        return category.domNode;
    }
    

    这里的例子:https://github.com/SitePen/dgrid/wiki/OnDemandList-and-OnDemandGrid 做了几乎相同的事情,除了它使用 put-selector,它只是构造一个 div,将小部件附加到它并返回新的 div。

    【讨论】:

    • 这里明显的问题是,您创建的 CategoryItem 小部件是否曾经被破坏?您返回可以通过 dgrid 销毁行来清理的 DOM 节点,但通常作为 dijit 实例的 Javascript 对象仅通过在其上调用 destroy() 来销毁。更新:找到了我自己的问题的答案:github.com/SitePen/dgrid/blob/master/doc/usage/… - 本质上,挂在 dgrid 上的“removeRow”上,并在 cellElement.widget 上调用 destroyRecursive。上面显示的简单方法包含危险的内存泄漏。
    猜你喜欢
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多