如何对插入到treestore中的项目进行排序,并将它们显示在treepanel中? extjs 4.07

时间:2012-06-22 14:13:51

标签: extjs tree controller extjs4 treepanel

我想知道如何将项目插入到已分类的树库中,如果在extjs中有一种方法可以执行此操作。然后,我希望将项目显示在树形图表中排序,尽管树形图中可能已经有一些节点;

所以,这个问题可能是,如何根据我店内的内容重新加载它所显示的内容。让我说清楚,我不想从某些数据源重新加载商店。我想重新加载面板以反映商店中包含的内容。最好的方法是什么?

1 个答案:

答案 0 :(得分: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);
    });
}