Javascript 程序性Dijit/树未出现在声明性Dijit/ContentPane中
有谁能帮我弄明白为什么Dojo1.8中可以使用这个功能,而1.9中却不能 在1.8中,树被放置在“pilotTreeContainer”内容窗格中。在1.9中,如果你在Firebug中查看,树就在那里,但从视觉上看,它只是显示一个加载图形。pilotTreeContainer在包含此代码的小部件的模板文件中声明。所有这些代码都在Javascript 程序性Dijit/树未出现在声明性Dijit/ContentPane中,javascript,dojo,dijit.layout,dijit.tree,Javascript,Dojo,Dijit.layout,Dijit.tree,有谁能帮我弄明白为什么Dojo1.8中可以使用这个功能,而1.9中却不能 在1.8中,树被放置在“pilotTreeContainer”内容窗格中。在1.9中,如果你在Firebug中查看,树就在那里,但从视觉上看,它只是显示一个加载图形。pilotTreeContainer在包含此代码的小部件的模板文件中声明。所有这些代码都在postreate方法中 var treeStore = lang.clone( store ); var treeModel = new ObjectStoreMod
postreate
方法中
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 );
我尝试在树和内容窗格上调用startup
在调试dijit/Tree代码时,似乎存在一个永远无法解决的延迟。当从_load函数调用时,它从_expandNode函数返回(当尝试展开根节点时this.\u expandNode(rn)。然后
)
在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);
}));
这棵树为什么不露出来?出了什么问题?回到这里(希望它能在Dojo1.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";
},
你能修改你的代码吗?不容易。我正在将一个复杂的基于Dijit的项目从1.8迁移到1.9,这只是其中的一小部分。你能发布整个小部件的代码吗?这可能是一个愚蠢的问题,但你正在调用pilotTree.startup()?在我看来,这与事件以意外/错误的顺序触发有关。从docs中,_widgetinterface.startup()
仅在向其添加第一个子项时调用,该子项应为this.pilotTreeContainer.set('content',pilotTree)代码>。是否有可能将树代码移动到单独的小部件上并在之前初始化它?也许像AJD建议的那样,pilotTree.startup()
正是我们所需要的。请参阅并在此处更详细地描述: