聚合物REST API不工作

问题描述:

empty data table我使用Web组件铁AJAX进行REST API调用下面这个教程http://frontendinsights.com/polymer-rest-api-using-iron-ajax/ 我正在获取这个数据,并使用predix数据表显示从UI API提取的数据使用数据表https://www.predix-ui.com/#/components/px-data-table/存储它基本上接受JSON格式的数据。但聚合物REST API不工作

<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格式,但是当我使用{{回购}}其示出其中包含的数据时,我使用{{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); 
} 
+0

伟大它的工作,你能解释一下我怎么样? – shashank

+0

this.githubrepository也应该是函数外部访问? – shashank

+0

https://www.polymer-project.org/2.0/docs/devguide/data-system#observable-changes –