0

我有一个与这篇文章非常相似的问题。

我的症状是一样的(父母和孩子一开始是平的。你可以“展开”父母让一些孩子在他们下面正确显示,然后你可以再次折叠他们让树显示它的样子应该)但提供的解决方案(将 store.getRootCollection() 传递给网格而不是仅仅存储)对我不起作用。如果我这样做,除了显示的标题外,我什么也得不到。

首先,我正在尝试使用dgrid 实验室中显示的代码使其工作(只需检查“网格功能”中的“树”),以尽可能多地消除我的错误。

我能想到的唯一与示例的代码不同的是,我在自定义小部件中制作了这个网格,并且我正在加载其他几个模块(我知道我以后会需要它们)

define(["dojo/_base/declare",
        "dojo/_base/lang",
        "dojo/dom",
        "dojo/dom-construct",
        "dojo/text!./templates/DefaultsWidget.html",
        "dijit/_WidgetBase",
        "dijit/_TemplatedMixin",
        "dijit/_WidgetsInTemplateMixin",
        "dijit/TitlePane",
        "dijit/layout/ContentPane",
        "dgrid/OnDemandGrid",
        "dgrid/Keyboard",
        "dgrid/Selection",
        "dgrid/extensions/DijitRegistry",
        "dgrid/Editor",
        "dgrid/Tree",
        "dstore/Memory",
        "dstore/Trackable",
        "dstore/Tree",
        "dojo/domReady!"],
		function(/*DOJO:*/declare, lang, dom, domConstruct, template,
				 /*DIJIT*/_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, TitlePane,ContentPane,
				 /*DGRID*/OnDemandGrid, Keyboard, Selection, DigitRegistry, Editor, Tree,
				 /*DSTORE*/Memory, Trackable, TreeStoreMixin){
			return declare("company.widgets.DefaultsWidget", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
				
				//The template defined with dojo.text
				templateString: template,				
				grid: null,
				
				postCreate: function(){
					
					var testData = [];
					var column;
					var i;
					var item;

					for (i = 0; i < 50; i++) {
						item = {};
						for (column in { First_Name: 1, Last_Name: 1 }) {
							item.id = i;
							item[column] = column + '_' + (i + 1);
						}
						if (i > 1) {
							item.hasChildren = false;
							item.parent = i % 2;
						}
						testData.push(item);
					}
					
					var store = new (declare([Memory, Trackable, TreeStoreMixin]))({
						data: testData
					});
					
					// Instantiate grid
					this.grid = new (declare([OnDemandGrid, Tree]))({
						collection: store,
						columns: {
							First_Name: {
								label: 'First Name',
								renderExpando: true
							},
							Last_Name: {
								label: 'Last Name'
							}
						},
					}, this.testGrid);
					

				},
				startup: function() {
					this.grid.startup();
				}

			}); //return declare
        }//function
);//define

这是网格与集合一起显示的方式:存储,

在此处输入图像描述

如果您需要更多信息,或者我错过了任何 SO 指南或礼仪,请告诉我,我很乐意编辑、改写等。

4

1 回答 1

0

似乎导致网格以这种方式显示的问题是根行中没有parent: null。实验室中显示的代码似乎无法按原样工作,并且需要我刚才提到的.getRootCollection()修复以及我引用的问题的修复。

于 2016-11-14T20:15:37.643 回答