(deep)
| 749 | } |
| 750 | |
| 751 | cloneNode(deep) { |
| 752 | const dataset = {} |
| 753 | Object.keys(this.$_dataset).forEach(name => { |
| 754 | dataset[`data-${tool.toDash(name)}`] = this.$_dataset[name] |
| 755 | }) |
| 756 | |
| 757 | const newNode = this.ownerDocument.$$createElement({ |
| 758 | tagName: this.$_tagName, |
| 759 | attrs: { |
| 760 | id: this.id, |
| 761 | src: this.src, |
| 762 | |
| 763 | ...dataset, |
| 764 | ...this.$$dealWithAttrsForCloneNode(), |
| 765 | }, |
| 766 | nodeType: this.$_nodeType, |
| 767 | nodeId: `b-${tool.getId()}`, // 运行时生成,使用 b- 前缀 |
| 768 | }) |
| 769 | |
| 770 | newNode.$_style.$$clone(this.$_style) |
| 771 | newNode.$_classList.$$clone(this.$_classList) |
| 772 | |
| 773 | // 属性 |
| 774 | if (this.$__attrs) { |
| 775 | const attrsMap = this.$_attrs.map |
| 776 | Object.keys(attrsMap).forEach(attrName => newNode.setAttribute(attrName, attrsMap[attrName])) |
| 777 | } |
| 778 | |
| 779 | if (deep) { |
| 780 | // 深克隆 |
| 781 | for (const child of this.$_children) { |
| 782 | newNode.appendChild(child.cloneNode(deep)) |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | return newNode |
| 787 | } |
| 788 | |
| 789 | appendChild(node) { |
| 790 | if (!(node instanceof Node)) return |
no test coverage detected