简书链接:写了一个dumpObject所有属性以及子属性的方法
文章字数:384,阅读全文大约需要1分钟
uniapp 的input是进行了自定义封装无法拿到内层的input, document在app那边无法使用,于是研究怎么拿到里面的,就把外层的input进行的dump分析。进行操作的时候发现很多重复 属性,需要去重。

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
dumpInfo(name = "root", node, maxDeep = 20) {
let hasDumpArr = []

function dump(name, node, maxDeep) {
let count = (name.split('/').length - 1)
let that = this
if (!node || typeof currentNode == 'string' ||
typeof currentNode == 'number') {
return;
}
if (Array.isArray()) {
for (let x = 0; x < currentNode.length; x++) {
let currentXX = currentNode[x]
dump(name + "[arr]", currentNode, maxDeep)

}
} else {

Object.keys(node).forEach(function(key) {
let currentNode = node[key]
console.log("dump nodeName:" + name, "key:" + key, 'attr', currentNode);
/* if (currentNode && typeof currentNode !== 'string' &&
typeof currentNode !== 'number') { */
if (key != "parentNode" && count <= maxDeep) { //key != "pageNode" &&

for (let x = 0; x < hasDumpArr.length; x++) {
let currentA = hasDumpArr[x]
if (currentA === currentNode) {
// console.log("忽略已存在的对象,避免死循环,key:"+name)
return;
}
}
hasDumpArr.push(currentNode)
dump(name + "/" + key, currentNode, maxDeep);
}
// }

});

}


}
dump(name, node, maxDeep);
console.log("dump finish attrs count:" + hasDumpArr.length + " ")
},

输出结果省略1万字

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
18:09:31.744 dump nodeName:ROOT/pageNode/_vnode,  key:shapeFlag,  attr,  [Number] 4  at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT/pageNode/_vnode, key:patchFlag, attr, [Number] 0 at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT/pageNode/_vnode, key:dynamicProps, attr, null at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT/pageNode/_vnode, key:dynamicChildren, attr, null at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT/pageNode/_vnode, key:appContext, attr, [object object] at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT/pageNode/_vnode, key:ctx, attr, null at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT/pageNode/_vnode, key:__page_container__, attr, [object object] at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT, key:parentNode, attr, [object object] at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT, key:_text, attr, null at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT, key:nodeId, attr, [Number] 21 at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT, key:nodeType, attr, [Number] 1 at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT, key:nodeName, attr, INPUT at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.744 dump nodeName:ROOT, key:childNodes, attr, [Object] [] at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.760 dump nodeName:ROOT, key:attributes, attr, [Object] {"data-v-09fd5285":"","type":"text","class":"uni-easyinput__content-input","password":false...} at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.760 dump nodeName:ROOT, key:style, attr, padding-right:;padding-left:10px; at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.760 dump nodeName:ROOT, key:vShow, attr, null at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.760 dump nodeName:ROOT, key:_html, attr, null at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.760 dump nodeName:ROOT, key:tagName, attr, INPUT at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.760 dump nodeName:ROOT, key:_vei, attr, [Object] {"onFocus":"function() { [native code] }","onBlur":"function() { [native code] }","onInput"...} at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:413
18:09:31.760 dump finish attrs count:3376 at uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue:437