简体   繁体   English

Polymer使用Array进行数据绑定

[英]Polymer use Array for data binding

I have this dom-repeat template and I wonder how to pass an Array into attribute. 我有这个dom-repeat模板,我想知道如何将Array传递给属性。

<dom-module id="my-element">
  <template>
        <template is="dom-repeat" items="{{headers}}">
          <span>{{item}}</span>
        </template>
  </template>
</dom-module>

<script>
  Polymer({
    is: "my-element",
    properties: {
      headers: Array
    }
  });
</script>

and then in an index.html file, I bind it like this: 然后在index.html文件中,我像这样绑定它:

<my-element headers="['abc', 'def']"></my-element>

I tried doing that but I nothing happened and I got the warning Polymer::Attributes: couldn't decode Array as JSON 我尝试过这样做,但我没有发生任何事情,我收到警告Polymer::Attributes: couldn't decode Array as JSON

Switch the double and single quotes. 切换双引号和单引号。 Polymer 1.0 requires correct JSON quotes, in 0.5 the reverse was accepted ( source ). Polymer 1.0需要正确的JSON引号,在0.5中反向接受( )。

<my-element headers='["abc", "def"]'></my-element>

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

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