我一直试图从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>
答案 0 :(得分:0)
当您在_c_studenten
函数中指定_members_get_response_handler
的值时,可以从last-response="{{_c_studenten}}"
中删除iron-ajax
。这可以防止将值设置两次。现在,您可以确保数据在Array中而不是Object(vaadin-grid需要数组数据)。这可能就是诀窍。如果没有,请确保iron-ajax获取的数据格式。