Я начинаю с кусочка кода, чтобы описание проблемы стало понятным.
У меня есть 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 для загрузки деревьев диджита в 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);
}
}
Все вышеперечисленные функции работают нормально. Теперь я хочу иметь функцию сброса, чтобы она могла стирать существующие деревья в div «first_content» и «second_content» и загружать эти 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"));
}
Понятия не имею, как реализовать функцию сброса. Не могли бы вы дать мне подсказку.