MCPcopy Create free account
hub / github.com/Tencent/kbone / cloneNode

Method cloneNode

packages/miniprogram-render/src/node/element.js:751–787  ·  view source on GitHub ↗
(deep)

Source from the content-addressed store, hash-verified

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

Callers 7

text-node.test.jsFile · 0.45
comment.test.jsFile · 0.45
element.test.jsFile · 0.45
initShadowRootMethod · 0.45
updateMethod · 0.45
jquery-3.6.0.jsFile · 0.45

Calls 5

$$createElementMethod · 0.80
$$cloneMethod · 0.80
appendChildMethod · 0.80
setAttributeMethod · 0.45

Tested by

no test coverage detected