2013-02-14 112 views
0

如果樹未展開,我無法獲取樹的節點。 像這樣使用。 tree.getNodeById(id);通過nodeid獲取樹節點

在此先感謝!

解決:這是我使用的代碼。

node_ids = [search_node_id,parent1_node_id,parent2_node_id] 

function select_node(node_ids,length,evt,e){ 
var node=leftnav_treePanel.getNodeById(node_ids[length]); //length is length of node_ids list 
var ajaxReq = ajaxRequest(node.attributes.url,0,"GET",true); 
ajaxReq.request({ 
    success: function(xhr) { 
     var response=Ext.util.JSON.decode(xhr.responseText); 
     if(length>0){ 
      removeChild(node); // method to remove existing childnodes 
      appendChild(response.nodes,node); // method to add child nodes from response 
      node.expand(); 
      select_node(node_ids,length-1,evt,e); 
     }else{ 
      node.fireEvent(evt,node,e); 
     } 
      }, 
    failure: function(xhr){ 
      Ext.MessageBox.alert(_("Failure") , xhr.statusText); 
    } 
}); 

}

+0

請提供編碼... – Reimius 2013-02-14 15:56:43

回答

0

以在因爲你沒有提供任何代碼怎麼在這裏就胡亂猜測。我認爲你有一個通過ajax異步加載treestore,並且存儲中的節點尚未加載到用戶頁面,這就是爲什麼javascript無法找到它們。

+0

oh.thanks的答覆。現在我正在從python中搜索節點路徑。所以現在我有這樣的節點路徑:root_node_id/node_id/child_node_id。現在,我必須展開路徑層次中的每個節點ID。或者有沒有其他方法....? – user1929916 2013-02-15 07:16:53

+0

tree.expandPath(path,null,function(success){alert(success)});返回false :(。展開每個ID是我猜的唯一解決方案。 – user1929916 2013-02-15 07:37:34

+0

如果您需要更多幫助,請提供代碼示例或jsFiddle。如果沒有更多信息,我不能告訴您有什麼問題。 – Reimius 2013-02-15 18:43:01