0

我是 Dojo 的新手,我正在使用 Dojo 1.8,这就是我想要做的——我创建了一个带有一些内容窗格的手风琴容器。这是有效的,当我单击页面上的某个按钮时,我正在调用一个函数 (del),在这里我想删除现有的手风琴容器及其内容窗格。然后用一些不同的内容窗格重新创建手风琴容器。调用 del 函数 acordian 容器不可见/创建后,我没有看到任何错误

require(["dijit/layout/AccordionContainer", "dijit/layout/ContentPane", "dojo/domReady!"], function( AccordionContainer, ContentPane){
var myPane = new ContentPane({id: "mycnpane",title: "This is a content pane", content: "<div id='lastContentPaneId'>my content pane</div>", style:"height:100px", doLayout: true});
var aContainer = new AccordionContainer({id: 'myacc', style:"height: 100%"}, "markup");
aContainer.addChild(new ContentPane({
title: "This is a content pane",
content: "Hi", style:"height: 80px", doLayout: false
}));
aContainer.addChild(new ContentPane({
title:"This is as well",
content:"<li><a href='javascript:void(0)' >report</a></li>", doLayout: true
}));
aContainer.addChild(new ContentPane({
title:"This too",
content:"Hello im fine.. thnx"
}));
aContainer.addChild(myPane);
aContainer.startup();
});

function del(){
require(["dijit/registry", "dojo/dom","dijit/layout/AccordionContainer", "dijit/layout/ContentPane", "dojo/domReady!"], function( registry, dom, AccordionContainer, ContentPane){
var aContainer = registry.byId("myacc");

console.log(aContainer);

if(aContainer){

aContainer.destroyRendering(false);
aContainer.destroy(false);

}

aContainer = new AccordionContainer({style:"height: 100%","isLayoutContainer": true, "doLayout": false}, "markup");
console.log('testacc container::'+aContainer);

var mypane = new ContentPane({ id: '123', title: 'newly', doLayout: true });
mypane.set('content','<ul><li>1</li><li>2</li></ul>');

var mypane1 = new ContentPane({ id: '1234', title: 'newly', doLayout: true });
mypane1.set('content','<ul><li>1</li><li>2</li></ul>');

aContainer.addChild(mypane);
aContainer.addChild(mypane1);
aContainer.startup();

});
}
4

1 回答 1

0

您可以简单地使用而不是

aContainer.destroyRendering(false);

aContainer.destroy(false);

利用

aContainer.destroyRecursive();

它适用于我使用的所有小部件。如果这不起作用,请尝试使用 placeAt 将手风琴放置在标记 div 中,看起来像这样

var aContainer = new AccordionContainer({id: 'myacc', style:"height: 100%"}); aContainer.placeAt("markup")

然后destroyRecursive

于 2013-09-17T14:58:16.087 回答