问题遇到的现象和发生背景
目前只写了可以改变前端显示的方法,把数据传到后端的方法还不会写T^T, 怎么写把数据传到后端的方法呢,已知树的级数排序由sortNum这个字段来决定(一级:1, 二级1.1 ,三级1.1.1 ),上移下移怎么给这个字段赋值然后传给后台呢,求赐教!关于element的树的问题都好复杂T^T T^T
问题相关代码,请勿粘贴截图
// 节点上移
nodeUp(node, data) {
const parent = node.parent;
const children = parent.data.children || parent.data;
const cIndex = children.findIndex((d) => d.poBomDetailId === data.poBomDetailId);
console.log(parent.level)
console.log(cIndex)
if (parent.level === 0 && cIndex === 0) {
return;
} else if (parent.level !== 0 && cIndex === 0) {
//不同父节点中移动
alert("不同父节点中移动");
} else if (
(parent.level === 0 && cIndex !== 0) ||
(parent.level !== 0 && cIndex !== 0)
) {
const tempChildrenNodex1 = children[cIndex - 1];
const tempChildrenNodex2 = children[cIndex];
this.$set(children, cIndex - 1, tempChildrenNodex2);
this.$set(children, cIndex, tempChildrenNodex1);
this.defaultExpandKeys[0] = data.poBomDetailId;
}
this.tree_key++;
console.log(this.tree_key)
},
// 节点下移
nodeDown(node, data) {
const parent = node.parent;
const children = parent.data.children || parent.data;
const cIndex = children.findIndex((d) => d.poBomDetailId === data.poBomDetailId);
const cLength = children.length - 1; // 最边上的节点
// const allLevel = store.data.length - 1; // 树的深度
if (data.leafNodeFlag === 'N' && cIndex === cLength) {
// 最最末的节点
return;
} else if (data.leafNodeFlag !== 'N' && cIndex === cLength) {
//父节点不同,leafNodeFlag 值为N
alert("不能移动");
} else if (
(data.leafNodeFlag === 'N' && cIndex !== cLength) ||
(data.leafNodeFlag !== 'N' && cIndex !== cLength)
) {
// 父节点相同
const tempChildrenNodex1 = children[cIndex + 1];
const tempChildrenNodex2 = children[cIndex];
this.$set(children, cIndex + 1, tempChildrenNodex2);
this.$set(children, cIndex, tempChildrenNodex1);
this.defaultExpandKeys[0] = data.poBomDetailId;
}
this.tree_key++;
},
我想要达到的结果
上移下移给sortNum这个字段重新赋值传给后台