Reputation: 900
I want to store few object in polymer declare property(array) and i will use those object later.
It will store object but method of that object not getting fired.
Workflow
_pageActive
will call_pageActive
will store all object to ObjectCollection
ObjectCollection
changed _showAllObject
will callthis.ObjectCollection
will printed in _showAllObject
this.ObjectCollection[0]._test is not a function
Below is my code,
<dom-module id="my-search">
<template>
<style>
:host {
display: table;
width: 100%;
}
</style>
<paper-icon-button id="search" icon="search"></paper-icon-button>
</template>
<script>
class MySearch extends Polymer.Element {
static get is() { return 'my-search'; }
static get properties() {
return {
pageActive: {
type: String,
observer: '_pageActive'
},
ObjectCollection: {
type: Array,
notify: true,
readOnly: false,
observer: '_showAllObject'
}
}
_pageActive(){
var thisElement = this;
var element1 = this.$.search;
this.ObjectCollection = [{thisElement },{element1}];
}
_showAllObject(){
console.log(this.ObjectCollection);
this.ObjectCollection[0]._test();
}
_test(){
alert("testing...!");
}
}
}
window.customElements.define(MySearch.is, MySearch);
</script>
</dom-module>
Why
_test()
method is not getting call asthis.ObjectCollection[0]
isthis
object
Upvotes: 2
Views: 110
Reputation: 3441
In order to observable object changes, use:
this.set('ObjectCollection', [thisElement, element1]);
instead of
this.ObjectCollection = [{thisElement },{element1}];
Then your _showAllObject
function will be fired.
Upvotes: 3