[英]Polymer Rest Api not working
我按照本教程http://frontendinsights.com/polymer-rest-api-using-iron-ajax/使用Web組件Iron Ajax進行REST api調用,我正在獲取此數據並使用predix數據表進行存儲以顯示獲取的內容使用數據表https://www.predix-ui.com/#/components/px-data-table/從ui上的api提取數據,該表基本上接受JSON格式的數據。
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-ajax/iron-
ajax.html">
<link rel="import" href="../../bower_components/px-data-table/px-data-
table.html">
<dom-module id="show-repositories">
<template>
<px-data-table
table-data="{{githubrepository}}"
language="en"
sortable>
<px-data-table-column name="repository"></px-data-table-column>
<px-data-table-column name="id" label="id"></px-data-table-column>
</px-data-table>
Repositories:
<span>{{githubrepository}}</span>
<span>{{repos}}</span>
<iron-ajax
id="requestRepos"
url="https://api.github.com/users/burczu/repos"
params='{"type":"all"}'
handle-as="json"
on-response="handleResponse">
</iron-ajax>
</template>
<script>
Polymer({
is: 'show-repositories',
properties: {
repos: {
type: Array
},
githubrepository:{
type: Array
}
},
ready: function () {
this.$.requestRepos.generateRequest();
},
handleResponse: function (data) {
this.repos = data.detail.response;
for (var i = 0; i < this.repos.length; i++) {
this.githubrepository[i] = {"id":this.repos[i].id,"name":this.repos[i].name}
}
console.log(this.repos);
console.log(this.githubrepository);
}
});
</script>
兩個控制台日志都顯示數據為json格式,但是當我使用{{repos}}時它顯示其中包含的數據,但是當我使用{{githubrepository}}時它不顯示數據,即使我也無法打印數據使用prredix Webcomponent。 我無法弄清楚這里出了什么問題?
更改您的js。
handleResponse: function (data) {
this.repos = data.detail.response;
var githubrepository = [];
for (var i = 0; i < this.repos.length; i++) {
githubrepository[i] = {"id":this.repos[i].id,"name":this.repos[i].name}
}
this.githubrepository = githubrepository;
console.log(this.repos);
console.log(this.githubrepository);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.