javascript - Polymer use Array for data binding - Stack Overflow

admin2025-04-19  0

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

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

Share Improve this question asked Aug 13, 2015 at 6:15 Nam ThaiNam Thai 8511 gold badge10 silver badges26 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745021765a280424.html

最新回复(0)