沒有真正的默認方式來做到這一點。什麼你將不得不做的是使用相同的模型樹,很簡單的東西像這樣在頁面上創建一個空店:
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);
});
}
SO,到底發生了什麼。我們必須重新加載整個商店才能更新樹形面板?它爲什麼這樣工作。我的同事不明白我爲什麼這樣做。我告訴他,這是我能找到的最簡單的方式,他不相信。 – Bbb
另外,我應該在哪裏創建sorStore? – Bbb
應使用與樹庫相關的相同模型創建和使用sortstore。這在語法上是最簡單的方法,儘管可能不是最優化的速度,但除非在父節點下有300多個節點,否則我認爲性能影響可以忽略不計。這看起來如此複雜的原因是因爲圖書館沒有提供默認的方法,它本身並不簡單。 – Reimius