Created
March 7, 2016 19:33
-
-
Save mmfilesi/2dce70685ee704e1e741 to your computer and use it in GitHub Desktop.
how works with arrays in polymer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Una explicación detallada en http://www.mmfilesi.com/?p=4528