我一直在尝试从 GW2 服务器获取 json 数据,由于跨域问题,该服务器不适用于 iron-ajax。比我尝试了这个 byutv-jsonp 并且有效。
现在的问题是我得到了正确数据的响应,但它没有触发响应处理程序。所以数据永远不会放在变量中:/
任何人都有提示,提示或线索?!
byutv 来源 http://coderfin.github.io/byutv-jsonp/components/byutv-jsonp/
<dom-module id="about-pagina">
<template>
<style include="shared-styles">
:host {
display: block;
}
</style>
<h1>about-pagina</h1>
<vaadin-grid id="grid" items="[[_c_studenten]]" selected-items="{{selected}}">
<vaadin-grid-column>
<template class="header">Account Name</template>
<template>
<div class="capitalized">[[item.name]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Rank</template>
<template>
<div class="capitalized">[[item.rank]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Date Joined</template>
<template>
<div class="capitalized">[[item.joined]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Docent</template>
<template>
<div class="capitalized">[[item.docent]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Lokaal</template>
<template>
<div class="capitalized">[[item.locatie]]</div>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Klas</template>
<template>
<div class="capitalized">[[item.klas]]</div>
</template>
</vaadin-grid-column>
</vaadin-grid-column>
</vaadin-grid>
<paper-button on-tap="derp" raised>Annuleren</paper-button>
<byutv-jsonp
id="ajax_members_get"
method="GET"
url="https://api.guildwars2.com/v2/guild/secretcode/members"
params='{"access_token":"secretcode"}'
handle-as="json"
last-response="{{_c_studenten}}"
on-response="_members_get_response_handler">
</byutv-jsonp>
</template>
<script>
Polymer({
is: 'about-pagina',
properties: {
c_visible: {
type: Boolean, /* true when element is the active visible item */
value: false,
observer: '_initializing',
},
_c_studenten: {
type: Array,
},
},
_initializing : function() {
if (this.c_visible) {
console.log("about-pagina");
this._members_get_request_handler();
}
},
_members_get_request_handler: function() {
console.log("_members_get_request_handler");
this.$.ajax_members_get.contentType="application/json";
this.$.ajax_members_get.body={
};
this.$.ajax_members_get.generateRequest();
},
_members_get_response_handler: function(request) {
console.log("_members_get_response_handler aantal studenten="+request.detail.response.length);
this._c_studenten = request.detail.response;
},
derp: function(){
console.log([[_c_studenten]]);
}
});
</script>
</dom-module>