1

我想知道如何将项目插入排序的树库中,如果 extjs 中有办法做到这一点。然后我想让这些项目出现在树面板中排序,尽管树面板中可能已经有一些节点;

所以,这个问题可能是,我如何让树形面板根据我商店中的内容重新加载它所显示的内容。让我明确一点,我不想从某个数据源重新加载商店。我想重新加载面板以反映商店中包含的内容。解决此问题的最佳方法是什么?

4

1 回答 1

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);
    });
}
于 2012-06-22T19:27:54.660 回答