程序化Dijit / Tree未出现在声明性Dijit / ContentPane中

时间:2014-04-19 10:56:04

标签: javascript dojo dijit.layout dijit.tree

任何人都可以帮我弄清楚为什么这在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上调用startup。

调试dijit / Tree代码,它认为有一个永不解决的延迟。当从_load函数调用时,它会从_expandNode函数返回(当尝试展开根节点this._expandNode(rn).then时)。

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);
}));

为什么树没有显示?出了什么问题?

1 个答案:

答案 0 :(得分:0)

回到这一点(希望它能在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";
},