2
我正在嘗試做類似於this question的工作,但是使用OnDemandList而不是OnDemandGrid。Dojo內的小工具dgrid OnDemandList
這裏是我迄今爲止
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
這裏的一個明顯的問題是,您創建的CategoryItem小部件是否曾經被銷燬?您返回可能由dgrid銷燬行的DOM節點,但通常只有通過調用destroy()才能銷燬作爲dijit實例的Javascript對象。更新:找到了我自己的問題的答案:https://github.com/SitePen/dgrid/blob/master/doc/usage/Working-with-Widgets.md - 本質上,掛鉤到dgrid上的'removeRow',和調用cellElement.widget上的destroyRecursive。上面顯示的簡單方法包含一個危險的內存泄漏。 – Neek