Polymer dom-repeat error parsing the array inside the object

╄→гoц情女王★ 提交于 2019-12-25 08:19:38

问题


Trying to fiddle with Polymer framework for my small project. Polymer dom-repeat error parsing the array inside the object

Following is the code invocation

  <paper-tabs scrollable selected={{selected}}>
    <template is="dom-repeat" items="{{rooms}}">
      <paper-tab>{{item.name}}</paper-tab>
    </template>
  </paper-tabs>

  <iron-pages selected="{{selected}}">
    <template is="dom-repeat" items="{{rooms}}">
      <div> <port-config room-config="{{item}}"></port-config> </div>
    </template>
  </iron-pages>

</template>

<script>
Polymer({
    is: "rooms-config",

    properties: {

    selected: {
        type:Number,
        value: 0,
      },

    rooms: {
        type: Array,
        value: function() {
          var testData = [
            {
              name: "Room1",
              maxPorts: 16,
              ports:{
                type: Array,
                value: function() {
                  var testData = [
                    {portName: "Port 1",portStatus: "true"},
                    {portName: "Port 2",portStatus: "true"},
                    {portName: "Port 3",portStatus: "true"},
                    {portName: "Port 4",portStatus: "true"},
                  ];
                  return testData;
                }
              }
            }
        }
     }
});

Following is my port-config declaration

<template>
<paper-material elevation="-1">
  <template is="dom-repeat" items="{{roomConfig.ports}}">
    <div class="container">
      <div class="flexchild">{{item.portName}}</div>
      <div class="flex1child">
        <paper-toggle-button toggles checked$="{{item.portStatus}}"></paper-toggle-button>
      </div>
      <div class="flex1child"><iron-icon icon="icons:settings"></iron-icon></div>
      </div>
  </template>
</paper-material>
</template>

<script>
Polymer({
    is: "port-config",
    properties: {

    roomConfig: {
      type: Object,
      value: function() { 
        return {};
      }
    }
  }
});

</script>

With this setup I am getting error [dom-repeat::dom-repeat]: expected array for items, found Object {}


回答1:


The problem should be that on the attribute's value you're passing functions instead of values.

For example:

rooms: {
        type: Array,
        value: function() {
          var testData = [
            {
              name: "Room1",
              maxPorts: 16,
              ports:{
                type: Array,
                value: function() {
                  var testData = [
                    {portName: "Port 1",portStatus: "true"},
                    {portName: "Port 2",portStatus: "true"},
                    {portName: "Port 3",portStatus: "true"},
                    {portName: "Port 4",portStatus: "true"},
                  ];
                  return testData;
                }
              }
            }
          ] // Also you've missed this close bracket. 
        }
     }

This room attribute should be writed like this:

rooms: {
  type: Array,
  value: [
    {
      name: "Room1",
      maxPorts: 16,
      ports: [
        {portName: "Port 1",portStatus: "true"},
        {portName: "Port 2",portStatus: "true"},
        {portName: "Port 3",portStatus: "true"},
        {portName: "Port 4",portStatus: "true"},
      ]
    }
  ]
}

There're other places on your code that you're doing this, so you'll need to fix them too.



来源:https://stackoverflow.com/questions/38835482/polymer-dom-repeat-error-parsing-the-array-inside-the-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!