移动节点不在jstree中使用sort插件

时间:2018-06-11 13:17:27

标签: jstree jstree-dnd

我在我的项目中使用JSTree插件和sort plugin.But因为sort插件我的移动节点没有工作。我发生这种情况因为在调用实际的move_node之前我的sort函数被触发。所以节点数据越来越多在调用的实际移动事件之前排序,并且由于此节点被安排在之前的状态中。

我的代码是这样的。

$("#jstree").jstree({
            "core": {
                "check_callback": function (op, node, par, pos, more) {
                    if (op =='move_node')
                    {
                        if (this.get_node(node).parent === this.get_node(par).id) {
                            isSortable = false;
                            return true;
                        } else { return false; }
                        //return  par.id == node.parent;
                    }
                    return true;
                },
                "data": {
                    'url': function (node) {

                        if (node.id === '#') {

                            return '/Template/GetMappingTree?touchpointId=' + touchpointId + '&orgAppSyncId=' + orgAppSyncId + '&orgId=' + orgId;
                        }
                        else {
                            if (node.data.Type == "attribute")
                            {
                                if (node.data.ChildUrl != '' && node.data.ChildUrl != null) {
                                    return node.data.ChildUrl;
                                }
                                else {
                                    return;
                                }
                            }

                            if (node.data.Type == "condition") {
                                if (node.data.ChildUrl != '' && node.data.ChildUrl != null) {
                                    return node.data.ChildUrl;
                                }
                                else {
                                    return;
                                }
                            }
                            if (node.data.Type == "variable") {
                                //var url = '/Template/VariableTree?touchpointId=' + touchpointId;
                                //return url;

                                if (node.data.ChildUrl != '' && node.data.ChildUrl != null) {
                                    return node.data.ChildUrl;
                                }
                                else {
                                    return;
                                }
                            }
                            if (node.data.Type === 'Tracking') {
                                if (node.data.ChildUrl != '' && node.data.ChildUrl != null) {
                                    return node.data.ChildUrl;
                                }
                                else {
                                    return;
                                }
                            }


                        }
                    },
                    'dataType': 'json'
                }


            },
            "multiple": false,
            "plugins": ['json_data', "table", "dnd", "actions", "wholerow", 'search', 'sort','crrm'],
            table: {
                columns: [
                    { header: "@(ViewBag.DestinationSchema + " Fields")", width: "30%" },
                    { value: "MappingData", header: "@("Mapping expression (for " + ViewBag.SourceSchema + ")")", width: "55%"  },
                    { format: loadActions, value: "actions", header: "Action", width: "15%" }
                ],
                resizable: false,
                draggable: false,
                contextmenu: false,
                headerContextMenu:false
            },
            sort: function (a, b) {
                debugger;
                a1 = this.get_node(a);
                b1 = this.get_node(b);
                if (a1.data!=null&& b1.data!=null)
                {

                    return (a1.data.order > b1.data.order) ? 1 : -1;
                }


            },
            dnd: {
                is_draggable: function (node) {
                    var nd = node;
                    if (node[0].data.IsMoveable == false) {
                        return false;
                    }
                    if (node[0].data.Type == "variable" || node[0].data.Type == "attribute")
                    {
                        return true;
                    }
                    if (node[0].parent == "trackingattribute") {
                        return true;
                    }
                    return false;
                },
                drop_finish: function (node) {
                    debugger;
                }
            }


        })

在移动节点中代码就像这样

 $('#jstree').on('move_node.jstree', function (e, data) {
        debugger;
        var parent = $('#jstree').jstree(true).get_node(data.node.parent);
        var position = 0;
        for (var i in parent.children) {
            var curChildren = $('#jstree').jstree(true).get_node(parent.children[i]);

            if (curChildren.data.order==-1)
            {
                continue;
            }
            curChildren.data.order = position;


            position = position + 1;
        }
        //var nodePosition = $.inArray(data.node.id, parent.children);

    });

0 个答案:

没有答案
相关问题