2014-04-19 33 views
2

任何人都可以幫我弄清楚爲什麼在Dojo 1.8中工作而不是在1.9中?程序化Dijit/Tree沒有出現在聲明式Dijit/ContentPane中

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

我已經嘗試在樹和內容面板上調用啓動。

調試dijit/Tree代碼,它看起來有一個延遲,永遠不會解決。當從_load函數中調用時,它會從_expandNode函數返回(當嘗試展開根節點this._expandNode(rn).then時)。

在的dijit /樹失敗的部分是這樣的:

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

爲什麼樹沒有顯示?出了什麼問題?

+0

你可以用你的代碼創建一個小提琴嗎? – Richard

+0

不容易。我將一個複雜的基於Dijit的項目從1.8遷移到1.9,這只是其中的一小部分。 – voidstate

+0

你可以發佈整個小部件的代碼嗎? – Philippe

回答

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"; 
},