javascript - Polymer: access polymer element objects -
i have polymer element called his-service:
<polymer-element name="gis-service" attributes="response url"> <template> <style> </style> <core-ajax id="ajax" auto url="{{url}}" method="get" contenttype = 'application/json' on-core-response="{{postsloaded}}" body="{{body}}" handleas="xml"> </core-ajax> </template> <script> polymer('gis-service', { created: function() { this.response = []; }, postsloaded: function() { this.response = []; this.labels = []; this.coordinates = []; x = this.$.ajax.response.getelementsbytagname("customerservicecenterdata"); (i=0;i<x.length;i++) { if (x[i].getelementsbytagname("language")[0].innerhtml == "en") { this.labels[i] = x[i].getelementsbytagname("label")[0].innerhtml; this.coordinates.push({ lat:x[i].getelementsbytagname("lat")[0].innerhtml, lng:x[i].getelementsbytagname("lng")[0].innerhtml }) } } console.log(this.coordinates); } }); </script> </polymer-element>
in index file, try access object labels , coordinates. following part of index:
<gis-service id="gservice" response="{{labels}}" url="someurl"> </gis-service> <script> var gis_service = document.queryselector('gis-service'); console.log(gis_service); </script>
as can see, trying access labels , coordinates through queryselector. however, when try labels instance via:
gis_service.labels
it gives me undefined. same thing variable coordinates. can see 2 variables when do: console.log(gis_service), cannot access them. appreciated.
define outside of function , should able use externally. format work .8 version. 1.0 version need use new format.
created: function() { this.response = []; }, labels: undefined, postsloaded: function() {
Comments
Post a Comment