Pass and declare parameter (array) in Polymer

1

I need to pass the following prametro to a polymer element:

[
  ["id", "nome",     "idade"],
  [1,    "matheus",  16],
  [2,    "cristian", 16],
  [3,    "pedro",    10],
  [4,    "henrique", 10]
]

How do I declare this variable (a matrix) in the propertie field?

    
asked by anonymous 31.03.2016 / 03:10

1 answer

0

Why do not you use an Array of objects?

Ex:

Polymer({

  is: 'hello',

  properties: {
    users: Array
  },

  ready: function() {

    this.users = [
       {id: 1, nome: 'Mateus', idade: 16},
       {id: 2, nome: 'Cristian', idade: 16},
       {id: 3, nome: 'Pedro', idade: 16}
    ];

  }

});

To access each user you can iterate this.users .

Ex:

this.users.forEach(function(user){
  console.log(user.id, user.nome, user.idade);
});

I hope I have helped.

    
21.04.2017 / 19:06