Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer use Array for data binding

I have this dom-repeat template and I wonder how to pass an Array into attribute.

<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:

<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

like image 413
Nam Thai Avatar asked Aug 13 '15 06:08

Nam Thai


1 Answers

Switch the double and single quotes. Polymer 1.0 requires correct JSON quotes, in 0.5 the reverse was accepted (source).

<my-element headers='["abc", "def"]'></my-element>
like image 102
Maria Avatar answered Oct 13 '22 02:10

Maria