![](/img/trans.png)
[英]dojo/dijit BorderContainer declarative example - but programmatic
[英]Programmatic Dijit/Tree Not Appearing in Declarative Dijit/ContentPane
谁能帮我弄清楚为什么它在Dojo 1.8中有效但在1.9中不可行?
在1.8中,该树放置在“ pilotTreeContainer”内容窗格中。 在1.9中,如果您在Firebug中查看,树就在那里,但从视觉上看,它只是显示一个加载图形。 在包含此代码的窗口小部件的模板文件中声明了pilotTreeContainer。 所有这些代码都在postCreate
方法中。
var treeStore = lang.clone( store );
var treeModel = new ObjectStoreModel(
{
store: treeStore,
query: { id: 'all' },
mayHaveChildren: function ( item ) // only ships have the unique attribute
{
return item.unique === undefined;
}
} );
var pilotTree = new Tree(
{
model: treeModel, // do we need to clone?
autoExpand: true,
showRoot: false,
title: 'Click to add',
openOnClick: true,
getDomNodeById: function ( id ) // new function to find DOM node
{
if ( this._itemNodesMap !== undefined && this._itemNodesMap[ id ] !== undefined && this._itemNodesMap[ id ][0] !== undefined ) {
return this._itemNodesMap[ id ][0].domNode;
}
else {
return null;
}
}
} );
this.pilotTree = pilotTree;
this.pilotTreeContainer.set( 'content', pilotTree );
我尝试在树和contentpane上都调用启动。
调试dijit / Tree代码后,似乎有一个延迟无法解决。 当从_load函数调用时(尝试扩展根节点this._expandNode(rn).then
它从_expandNode函数返回。
dijit / Tree中失败的部分是这样的:
// Load top level children, and if persist==true, all nodes that were previously opened
this._expandNode(rn).then(lang.hitch(this, function(){
// Then, select the nodes specified by params.paths[].
this.rootLoadingIndicator.style.display = "none";
this.expandChildrenDeferred.resolve(true);
}));
为什么树不显示? 怎么了?
回到这个问题(希望可以在Dojo 1.10中解决),我找到了解决方法。
我将树抽象到其自己的模块中,使用placeAt()
将其添加到容器中,而不是使用this.pilotTreeContainer.set( 'content', pilotTree );
:
// dijit/Tree implementation for pilots
pilotTree = new PilotTree(
{
model: treeModel
} );
// add to container
pilotTree.placeAt( this.pilotTreeContainer.containerNode );
pilotTree.startup();
然后强迫它在树的startup()
方法中显示其内容:
startup: function()
{
this.inherited( arguments );
// force show!
this.rootLoadingIndicator.style.display = "none";
this.rootNode.containerNode.style.display = "block";
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.