Pass and declare parameter (matrix) in Polymer

Asked

Viewed 32 times

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

as I declare this variable (a Matrix) in the propertie field?

1 answer

0

Why not use an object array?

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 of the users you can iterate the this.users.

Ex:

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

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.