Usando iron-ajax di Google Polymer, come caricare un file json da qualsiasi server web: polimero
Sto sviluppando un'applicazione web Google Polymer. Ha bisogno di caricare file JSON da un server web. Sto usando iron-ajax, come raccomandato nella documentazione Polymer.
Ho copiato il codice di esempio dalla demo nel mio progetto e l'ho provato molte volte, ma tutti i test fallirono. Per favore mostrami cosa c'è di sbagliato nel mio codice.
modello
......
<iron-ajax
on-response="ontap"
auto
url="test.json"
// for one test, I put test.json in the same folder as this Polymer html
// for other tests, I put test.json on some web servers, using correct URLs
//for example: http://www.test.com/test.json
handle-as="json"
last-response="{{ajaxR}}"
debounce-duration="300"> </iron-ajax>
.......
Funzione polimerica
ontap:function(ev){
alert(ev.detail);//it says "object HTMLElement"
alert(this.ajaxR);//it says null
}
.......
test.json
[{song:"song1"}]
risposte:
0 per risposta № 1ajaxR
diventa una proprietà sul tuo elemento. Per accedervi puoi usare this.ajaxR
.
ontap: function () {
alert(this.ajaxR);
alert(this.ajaxR[0].song);
}
Commenti (0)
Aggiungi un commento