简体   繁体   English

PolymerJS:如何输出模型数据?

[英]PolymerJS: How to output Model data?

Is there a way to output all model data of polymer elements? 有没有办法输出聚合物元素的所有模型数据?

I would like to output each property and their value to the view. 我想将每个属性及其值输出到视图中。

I know vue accomplishes this, by using 我知道vue通过使用来完成这个

{{ $data | json }}

But Vue also has a data attribute that is dumpable . 但是Vue也有一个可转储的数据属性。 Not sure if it is even possible in polymer to dump every property and their value into the view. 不确定聚合物是否甚至可以将每个属性及其值转储到视图中。

I'd like to use something similar with polymer. 我想用类似聚合物的东西。 But how? 但是怎么样?

I know doing something like this doesn't work: 我知道做这样的事情不起作用:

{{ $properties }}

As far as I know, there is no filters in data bindings in PolymerJS like vue has. 据我所知,PolymerJS中没有像vue那样的数据绑定过滤器。

But you can use so called Computed binding : 但是你可以使用所谓的Computed binding

<dom-module id="view">

  {{dump(model)}}

  <script>
    Polymer({
      is: 'view',
      properties: {
        model: Object       
      },
      dump: function(model) {
        return JSON.stringify(model, null, ' ');
      }
    });
  </script>

</dom-module>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM