Polymer 1.x:如何打印 Polymer 元素的所有属性?
Polymer 1.x: How to print all the properties of a Polymer element?
如何将已导入自定义元素的元素的所有属性打印到控制台。
例如,我有一个自定义元素 my-el
,我在该元素中导入了一个 firebase-document
元素。我想通过观察 firebase-document
在特定时间点的所有属性的值来了解 firebase-document
元素模型的当前状态。
我的-el.html
<firebase-document id="document"
app-name="my-app"
data="{{data}}">
</firebase-document>
...
foo: function() {
...
var doc = this.$.document;
// Neither of the following "works" (see below for definition)
console.log('doc', doc);
console.log('doc.properties', doc.properties);
}
通过 works,我的意思是它不会产生将对象打印到控制台的预期行为。该对象是 doc
对象的 all the properties。
评论总结:
使用
console.dir( doc );
您可以使用 console.dir()
,但您也可以在标准 console.log()
调用中使用 %o
替换字符串:
console.log( 'doc=%o', doc );
list of substition strings 可在 MDN 网站上找到。
如何将已导入自定义元素的元素的所有属性打印到控制台。
例如,我有一个自定义元素 my-el
,我在该元素中导入了一个 firebase-document
元素。我想通过观察 firebase-document
在特定时间点的所有属性的值来了解 firebase-document
元素模型的当前状态。
<firebase-document id="document"
app-name="my-app"
data="{{data}}">
</firebase-document>
...
foo: function() {
...
var doc = this.$.document;
// Neither of the following "works" (see below for definition)
console.log('doc', doc);
console.log('doc.properties', doc.properties);
}
通过 works,我的意思是它不会产生将对象打印到控制台的预期行为。该对象是 doc
对象的 all the properties。
评论总结:
使用
console.dir( doc );
您可以使用 console.dir()
,但您也可以在标准 console.log()
调用中使用 %o
替换字符串:
console.log( 'doc=%o', doc );
list of substition strings 可在 MDN 网站上找到。