mirror of
https://github.com/jlengrand/polymer-array-bubble-up-example.git
synced 2026-03-10 08:41:23 +00:00
50 lines
1.5 KiB
HTML
50 lines
1.5 KiB
HTML
<link rel="import" href="/polymer/polymer.html">
|
|
<link rel="import" href="/components/another-component/another-component.html">
|
|
|
|
<dom-module id="example-component">
|
|
<template>
|
|
<style>
|
|
:host {
|
|
display: block;
|
|
}
|
|
</style>
|
|
|
|
<h1>Example</h1>
|
|
|
|
<h2>List of elements</h2>
|
|
<template is="dom-repeat" items="{{elements}}" as="item" indexAs="index">
|
|
<another-component element="{{item}}" index={{index}} ident$="{{index}}"></another-component>
|
|
</template>
|
|
|
|
</template>
|
|
<script>
|
|
var fred = {"name": "fred"};
|
|
var tom = {"name": "tom"};
|
|
|
|
Polymer({
|
|
is: 'example-component',
|
|
properties: {
|
|
elements: {
|
|
type: Array,
|
|
value: [{"name": "Main1", "person": fred}, {"name": "Main2", "person": tom}, {"name": "Main3", "person": fred}],
|
|
notify: true
|
|
}
|
|
},
|
|
|
|
attached: function(){
|
|
this.addEventListener('change-name', function (e) {
|
|
console.log("fired");
|
|
|
|
this.elements[e.detail.index].person.name = e.detail.newPersonName;
|
|
|
|
for(var i =0; i< this.elements.length; i++){
|
|
this.notifyPath('elements.'+i+'.person.name');
|
|
}
|
|
console.log(this.elements);
|
|
|
|
});
|
|
}
|
|
|
|
});
|
|
</script>
|
|
</dom-module> |