switchChainNode(fromNode, targetNode) { let attrFromNode = { index: fromNode.index, prev: fromNode.prev, next: fromNode.next }; let attrTargetNode = { index: targetNode.index, prev: targetNode.prev, next: targetNode.next }; let isSibling = attrTargetNode.prev === fromNode; // 交换index // 更改prev next if (attrFromNode.prev) { attrFromNode.prev.next = targetNode; } if (attrTargetNode.next) { attrTargetNode.next.prev = fromNode; } targetNode.prev = attrFromNode.prev; fromNode.next = attrTargetNode.next; if (isSibling) { targetNode.next = fromNode; fromNode.prev = targetNode; } else { targetNode.next = attrFromNode.next; fromNode.prev = attrTargetNode.prev; if (attrTargetNode.prev) { attrTargetNode.prev.next = fromNode; } if (attrFromNode.next) { attrFromNode.next.prev = targetNode; } } fromNode.index = attrTargetNode.index; targetNode.index = attrFromNode.index; }