1

我有一个treeStore('planScreenStore'),我通过以下方式访问它:

        updateStore : function() {

                    rootNodeID = globals.GlobalModel.planList.scope._id;
                    var planScreenStoreRootNode = this.planScreenStore.getRootNode();

                    if (!(planScreenStoreRootNode === undefined)) {
                        planScreenStoreRootNode.removeAll();
                    }
                    if (globals.GlobalModel.planList.children.length > 0) {
                        planScreenStoreRootNode.appendChild(
                                globals.GlobalModel.planList.children);
                        globals.GlobalModel.planList.children = planScreenStoreRootNode;
                        globals.GlobalModel.planListForCreateNewPlan = planScreenStoreRootNode;
                    }

我必须根据其字段“文本”对 treeStore 进行排序。我已经能够通过以下两种方式做到这一点:

     updateStore : function() {
                    debugger;
                    rootNodeID = globals.GlobalModel.planList.scope._id;
                    var planScreenStoreRootNode = this.planScreenStore.getRootNode();

                    if (!(planScreenStoreRootNode === undefined)) {
                        planScreenStoreRootNode.removeAll();
                    }
                    if (globals.GlobalModel.planList.children.length > 0) {
                        planScreenStoreRootNode.appendChild(
                                globals.GlobalModel.planList.children);
                        globals.GlobalModel.planList.children = planScreenStoreRootNode;
                        globals.GlobalModel.planListForCreateNewPlan = planScreenStoreRootNode;
                    }
                        this.planScreenStore.sort('text','ASC');

另一个:

     updateStore : function() {
                    debugger;
                    rootNodeID = globals.GlobalModel.planList.scope._id;
                    var planScreenStoreRootNode = this.planScreenStore.getRootNode();

                    if (!(planScreenStoreRootNode === undefined)) {
                        planScreenStoreRootNode.removeAll();
                    }
                    if (globals.GlobalModel.planList.children.length > 0) {
                        planScreenStoreRootNode.appendChild(
                                globals.GlobalModel.planList.children);
                        globals.GlobalModel.planList.children = planScreenStoreRootNode;
                        globals.GlobalModel.planListForCreateNewPlan = planScreenStoreRootNode;
                    }


                    planScreenStoreRootNode.sort(function(n1, n2) {
                        debugger ;
                        var v1 = n1.data['text'].toUpperCase();
                        var v2 = n2.data['text'].toUpperCase();

                        if (v1 < v2)
                            return -1;
                        else if (v1 > v2)
                            return 1;
                        return 0;
                    });  

我用这两种方法都得到了想要的结果,但不知何故,在这两种情况下,我的应用程序在执行排序后崩溃,而它在没有应用任何排序的情况下完全正常工作。是否与我访问 NodeInterface (planScreenRootNode) 的方式有关。我该如何解决这个问题?

4

0 回答 0