【发布时间】:2011-03-06 11:20:37
【问题描述】:
我从一段一段代码开始,以便问题描述变得清晰。
-
我有一段 HTML 代码:
<div id="center" class="column" dojoType="dijit.layout.TabContainer"><div id="first" dojoType="dijit.layout.ContentPane" title="first" selected="true"> <div id="first_content"></div> </div> <div id="second" dojoType="dijit.layout.ContentPane" title="second"> <div id="second_content"></div> </div></div> 我有一个 javascript 函数可以将 dijit 树加载到 HTML 中:
函数加载()
{
//load data
dojo.xhrGet(firsthierarchy("first_content", "file1.json"));
dojo.xhrGet(secondhierarchy("second_content", "file2.json"));
}
function firsthierarchy(node, url){
return {
url: url,
node: dojo.byId(node),
handleAs: "json",
load: loadfirsthierarchy
};
}
function secondhierarchy(node, url){
return {
url: url,
node: dojo.byId(node),
handleAs: "json",
load: loadsecondhierarchy
};
}
function loadfirsthierarchy(data, xhr)
{
if(xhr.args.node)
{
store1 = new dojo.data.ItemFileWriteStore({data: data});
treeModel1 = new dijit.tree.ForestStoreModel({
store: store1,
query: {
"type": "continent"
},
rootId: "root",
rootLabel: "Continents",
childrenAttrs: ["children"]
});
tree1 = new dijit.Tree({
model: treeModel1,
},xhr.args.node.id);
}
}
function loadsecondhierarchy(data, xhr)
{
if(xhr.args.node)
{
store2 = new dojo.data.ItemFileWriteStore({data: data});
treeModel2 = new dijit.tree.ForestStoreModel({
store: store2,
query: {
"type": "continent"
},
rootId: "root",
rootLabel: "Continents",
childrenAttrs: ["children"]
});
tree2 = new dijit.Tree({
model: treeModel2,
},xhr.args.node.id);
}
}
以上所有功能都可以正常工作。现在,我想要一个重置功能,以便它可以清除“first_content”和“second_content”div 中的现有树,并使用具有新内容的新树加载这些 div。例如:
函数重置()
{
// here I want to completely wipe out the exiting trees in all of the dojo contentpanes.
// And I want to load the contentpanes with entire new set of data.
// Maybe like :
// dojo.xhrGet(firsthierarchy("first_content", "file3.json"));
// dojo.xhrGet(secondhierarchy("first_content", "file4.json"));
}
我不知道如何实现重置功能。你能不能给我一个线索。
【问题讨论】: