![](/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.