正在获取 iron-data-table 以呈现演示数据

Getting iron-data-table to render demo data

When I run my code in this JSbin, I expect the iron-data-table to render with populated data similar to the way it does on this demo page。相反,只有 table headers 渲染但其余单元格无法填充。

可以对 JSbin 进行哪些更改以实现所需的行为?

http://jsbin.com/hepebapori/1/edit?html,控制台,输出
<!DOCTYPE html>
<html>  
  <head>
    <base href="https://polygit.org/polymer+:master/components/">
    <link rel="import" href="polymer/polymer.html">

    <script src="webcomponentsjs/webcomponents-lite.min.js"></script>

    <link rel="import" href="iron-ajax/iron-ajax.html">
    <link rel="import" href="paper-button/paper-button.html">

    <link href="https://rawgit.com/saulis/iron-data-table/master/iron-data-table.html" rel="import">

  </head>
  <body>
    <dom-module id="x-foo">
      <template>
        <style>
        </style>
        <paper-button on-tap="msg">Click Me</paper-button>

        <iron-ajax auto
          url="https://saulis.github.io/iron-data-table/demo/users.json" 
          last-response="{{users}}"
          >
        </iron-ajax>
        <iron-data-table selection-enabled items="[[users.results]]">
          <data-table-column name="Picture" width="50px" flex="0">
            <template>
              <img src="[[item.user.picture.thumbnail]]">
            </template>
          </data-table-column>
          <data-table-column name="First Name">
            <template>[[item.user.name.first]]</template>
          </data-table-column>
          <data-table-column name="Last Name">
            <template>[[item.user.name.last]]</template>
          </data-table-column>
          <data-table-column name="Email">
            <template>[[item.user.email]]</template>
          </data-table-column>
        </iron-data-table>

      </template>
      <script>
        (function(){
          'use strict';
          Polymer({
            is: 'x-foo',
            msg: function() {
              console.log('This proves Polymer is working!');
            },
          });
        })();
      </script>
    </dom-module>
    <x-foo></x-foo>
  </body>
</html>

您的问题是 iron-data-table 的导入。仅使用 rawgit 不会产生魔力,因为您需要使用诸如 polygit 之类的代理服务器来使 webcomponents 工作(您已经像这样加载 Polymer,但不是 iron-data-table)。

由于表现平庸 documentation 我花了一段时间才弄清楚如何将聚合物导入与 iron-data-table.

相结合

需要的两个配置是polymer+:masteriron-data-table+Saulis+:master

综合起来,您的 base 标签如下所示:

<base href="https://polygit.org/polymer+:master/iron-data-table+Saulis+:master/components/">

有了这个,您可以像导入其他元素一样导入元素:

<link rel="import" href="iron-data-table/iron-data-table.html">

Working JSbin(在 Google Chrome 中测试)

要开始在您的项目中使用 iron-data-table,您必须:

  1. 下载包:
bower i iron-data-table -S

bower install --save PolymerElements/iron-ajax
  1. 创建 html 引用这些包的文件:
<html>
<head>
    <title></title>
  <meta charset="utf-8" />
    <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/iron-data-table/iron-data-table.html">
</head>
<body>
    <template is="dom-bind">
        <iron-ajax url="data.json" last-response="{{data}}" auto></iron-ajax>
        <iron-data-table items="[[data]]">
            <data-table-column name="First Name">
                <template>
                    [[item.name.first]]
                </template>
            </data-table-column>
            <data-table-column name="Last Name">
                <template>
                    [[item.name.last]]
                </template>
            </data-table-column>
        </iron-data-table>
    </template>
</body>
</html>
  1. 在 html 文件所在的相同位置创建 data.json 文件:
[
  {"name": {
    "title": "miss",
    "first": "donna",
    "last": "davis"
  }},
  {
    "name": {
      "title": "mr",
      "first": "samuel",
      "last": "kelley"
    }
  },
  {"name": {
    "title": "ms",
    "first": "katie",
    "last": "butler"
  }}
]