2012-06-22 57 views
1

我想知道如何將項目插入到已分類的樹存儲中,如果extjs中有某種方法可以執行此操作。然後我想讓這些項目出現在一個treepanel中,儘管treepanel中可能已經有了一些節點;如何對插入到treestore的項目進行排序,並使它們在treepanel中顯示排序? extjs 4.07

所以,這個問題可能是,我如何有一個treepanel重新加載它顯示什麼基於我的商店內。讓我明確一點,我不想從某些數據源重新加載商店。我想重新加載面板以反映商店內包含的內容。什麼是最好的方式去做這件事?

回答

0

沒有真正的默認方式來做到這一點。什麼你將不得不做的是使用相同的模型樹,很簡單的東西像這樣在頁面上創建一個空店:

var mySortStore = Ext.create("Ext.data.Store", { 
    model: "MyTreeStore", 
    data: [] 
}); 

然後,當你去到節點添加到樹,使用這個功能代替:

function addNodeSorted(node, childToBeAdded){ 
    //clear the store from previous additions 
    mySortStore.removeAll(); 
    //remove old sorters if they are dynamically changing 
    mySortStore.sort(); 
    //add the node into the tree 
    node.appendChild(childToBeAdded); 
    var cn = node.childNodes, 
     n; 

    //remove all nodes from their parent and add them to the store 
    while ((n = cn[0])) { 
     mySortStore.add(node.removeChild(n)); 
    } 

    //then sort the store like you would normally do in extjs, what kind of sorting you want is up to you 
    mySortStore.sort('height', 'ASC');//this is just an example 

    //now add them back into the tree in correct order 
    mySortStore.each(function(record){ 
     node.appendChild(record); 
    }); 
} 
+0

SO,到底發生了什麼。我們必須重新加載整個商店才能更新樹形面板?它爲什麼這樣工作。我的同事不明白我爲什麼這樣做。我告訴他,這是我能找到的最簡單的方式,他不相信。 – Bbb

+0

另外,我應該在哪裏創建sorStore? – Bbb

+0

應使用與樹庫相關的相同模型創建和使用sortstore。這在語法上是最簡單的方法,儘管可能不是最優化的速度,但除非在父節點下有300多個節點,否則我認爲性能影響可以忽略不計。這看起來如此複雜的原因是因爲圖書館沒有提供默認的方法,它本身並不簡單。 – Reimius

相關問題