【问题标题】:Polymer 1.x: How to print all the properties of a Polymer element?Polymer 1.x:如何打印 Polymer 元素的所有属性?
【发布时间】:2017-01-07 01:58:34
【问题描述】:

如何将我已导入自定义元素的元素的所有属性打印到控制台。

例如,我有一个自定义元素 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,我的意思是它不会产生将对象打印到控制台的期望行为。对象是all the propertiesdoc 对象。

【问题讨论】:

  • 你试过console.dir( doc )吗?
  • @Supersharp:行得通。谢谢。

标签: polymer polymer-1.0 custom-element


【解决方案1】:

您可以使用console.dir(),但也可以在标准console.log() 调用中使用%o 替换字符串:

console.log( 'doc=%o', doc );

list of substition strings 可在 MDN 的网站上找到。

【讨论】:

    【解决方案2】:

    来自 cmets 的总结:

    使用

    console.dir( doc );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多