Skip to content

Instantly share code, notes, and snippets.

@mmfilesi
Created March 7, 2016 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmfilesi/2dce70685ee704e1e741 to your computer and use it in GitHub Desktop.
Save mmfilesi/2dce70685ee704e1e741 to your computer and use it in GitHub Desktop.
how works with arrays in polymer
<dom-module id="foo-component">
<template>
<style>
</style>
<button on-tap="addFruit">Añadir fruta</button>
La primera fruta es: {{getFruit(fruits.*, 0)}}
</template>
<script>
Polymer({
is: 'foo-component',
properties: {
fruits: {
Type: Array,
value: ['coco', 'cerezas', 'higos']
}
},
getFruit(arr, index) {
return arr.base[index];
},
observeFruits: function(changes) {
if ( !changes ) {
return;
}
changes.indexSplices.forEach(function(item) {
var i = 0;
var len = item.removed.length;
console.log('Los elementos suprimidos son: ');
for (; i<len; i++) {
console.log(item.removed[i]);
}
console.log('y la operación realizada ha sido un ', item.type);
});
},
addFruit: function() {
this.unshift('fruits', 'aguacates');
}
})
</script>
</dom-module>
@mmfilesi
Copy link
Author

mmfilesi commented Mar 7, 2016

Una explicación detallada en http://www.mmfilesi.com/?p=4528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment