我昨天开始学习道场,所以请原谅我的无知......
我的期望是动态创建一个手风琴并在手风琴的内容窗格中显示一个网格。为此,我创建了带有 2 个内容窗格的手风琴小部件,当处理内容窗格时,我创建了一个自定义小部件并添加到内容窗格中(这是必需的,即,我不能直接添加数据网格)。创建自定义网格后,它会创建一个计时器,并在计时器结束时填充网格并显示它。
现在,如果你在浏览器中运行它(当然在正确的路径中使用 dojo),你会注意到在大约 8 秒超时后,手风琴窗格显示网格(以一种笨拙的方式,我仍然需要弄清楚为什么,任何帮助会很大)。但是之后:
如果我在刷新后立即(在 8 秒内)打开第二个窗格并保持第一个窗格关闭直到 8 秒后然后打开第一个窗格,似乎什么都没有。Dojo 专家可以帮我理解为什么吗?谢谢!
<html>
<head>
<style type="text/css">
@import "dojo/dijit/themes/tundra/tundra.css";
@import "dojo/dijit/themes/tundra/layout/AccordionContainer.css";
@import "dojo/resources/dojo.css"
</style>
<script type="text/javascript" src="dojo/dojo/dojo.js" djConfig="parseOnLoad: true, isDebug: true"></script>
</head>
<script>
/*
The source is organized like this:
head;
script;
timer proc;
grid widget;
constructor, postCreate, onElapse method where the grid is populated.
Accordion widget:
construct, postCreate panes are created and added.
*/
// Mock backend
var timerThis = undefined;
function onElapse()
{
timerThis.onElapse();
}
// Grid Widget declaration.
dojo.provide("widgets.GridWidget");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
// Grid widget class.
dojo.declare("widgets.GridWidget", [ dijit._Widget, dijit._Templated ], {
// Members
templateString : '<div id="${id}" dojoAttachPoint="widgets_GridWidget"></div>',
srcNodeRef : null,
grid : null,
timer : null,
// Constructor
constructor : function(params, srcNodeRef)
{
this.inherited(arguments);
this.id = "myUniqueId";
this.srcNodeRef = srcNodeRef;
// Copy this so timer onElapse() can access.
timerThis = this;
this.timer = setTimeout("onElapse()", 8000);
},
// Member invoked from global onElapse.
onElapse : function()
{
var layout =
[
{ name: 'Name', field: 'name', width: 'auto' },
{ name: 'Color', field: 'color', width: 'auto' }
];
var store =
{
data :
{
items :
[
{ name : 'John Doe', color: 'green' },
{ name : 'Jane Doe', color: 'red' }
]
}
};
// Create a grid and startup.
this.grid = new dojox.grid.DataGrid({
store: new dojo.data.ItemFileReadStore(store),
clientSort: true,
rowSelector: '20px',
structure: layout
}, this.srcNodeRef);
this.widgets_GridWidget.appendChild(this.grid.domNode);
this.grid.startup();
}
});
// Create an accordion container that will display the grid in one of its pane.
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dijit.layout.ContentPane");
dojo.declare("widgets.AccordionWidget", [ dijit._Widget, dijit._Templated ],
{
templateString : '<div id="AccordionWidget" dojoAttachPoint="widgets_AccordionWidget"></div>',
srcNodeRef : null,
constructor : function(params, srcNodeRef)
{
this.inherited(arguments);
this.srcNodeRef = srcNodeRef;
},
postCreate : function()
{
this.inherited(arguments);
var container = new dijit.layout.AccordionContainer({
style : "height: 100px"
},
this.widgets_AccordionWidget.id + "_Container");
var panes =
[
new dijit.layout.ContentPane({
title: "First pane"
}),
new dijit.layout.ContentPane({
title: "Second pane"
})
];
container.addChild(panes[0]);
container.addChild(panes[1]);
this.widgets_AccordionWidget.appendChild(container.domNode);
// Scope closure
{
var pane = panes[0];
// var pane = panes[1];
var wdg = undefined;
pane.set("onShow",
function()
{
if (wdg === undefined)
{
wdg = new widgets.GridWidget({}, pane.id + "_1");
wdg.placeAt(pane.domNode);
}
}
);
}
this.widgets_AccordionWidget.appendChild(container.domNode);
container.startup();
}
});
dojo.addOnLoad(function()
{
dojo.require('dojo.parser');
});
dojo.ready(function()
{
dojo.parser.parse();
var wdg = new widgets.AccordionWidget({}, dojo.byId("root"));
});
</script>
<body class="tundra">
<div id="root"></div>
</body>
</html>