我有一棵树,它按节点数据中的订单号排序。但是,我试图在树中拖放节点后对节点进行排序。我可以不成功更新订单,但节点没有在树上移动。将节点再次拖动到该位置后,它可以正常工作。
$("#projectIssues").jstree({
sort: treeSortFunction,
json_data: { data: nodes },
ui: { "select_limit": 1 },
themes: { url: themeUrl },
core: { "check_callback": true },
plugins: ["themes", "json_data", "ui", "sort", "dnd", "crrm"],
crrm: {
"move": {
"default_position": "inside",
"check_move": function(n) {
return Project.ViewModel.DragDropNode(n);
}
}
}
}).bind("move_node.jstree", function (e, d) {
console.log(d.rslt.cp);
var node = _tree._get_node(d.rslt.o);
node.data("OrderNo", d.rslt.cp);
console.log("Current Node Order:" + node.data("OrderNo"));
Project.ViewModel.UpdateNodeOrder(d.rslt.np, d.rslt.o);
}).bind("dblclick.jstree", doubleClickNode)
.bind("select_node.jstree", function (event, result) {
var node = result.rslt.obj;
Project.ViewModel.UpdateEditor(node);
});
更新订单号
的方法 self.UpdateNodeOrder = function (parentNode, curNode) {
var childNodes = _tree._get_children(parentNode);
var node = _tree._get_node(curNode);
for (var i = node.data("OrderNo"); i <= childNodes.length-1; i++) {
var n = _tree._get_node(childNodes[i]);
if (n != undefined) {
if (node.data("Name") !== n.data("Name")) {
n.data("OrderNo", i + 1);
}
console.log(n.data("Name") + " " + n.data("OrderNo"));
}
}
};
答案 0 :(得分:0)
添加了_tree.sort(parentNode.children(“ul”),它完成了这个技巧