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

时间:2016-07-31 07:14:06

标签: javascript polymer polymer-1.0 iron-data-table

When I run my code in this JSbin,我希望iron-data-table使用与on this demo page类似的填充数据进行渲染。相反,只有表头呈现,但其余的单元格无法填充。

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

http://jsbin.com/hepebapori/1/edit?html,console,output
<!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>

2 个答案:

答案 0 :(得分:1)

您的问题是导入 GeckoButtonElement button = new GeckoButtonElement(geckoWebBrowser1.Document.GetHtmlElementById("u_jsonp_7_d").DomObject); button.Click(); 。仅仅使用rawgit不会发挥作用,因为你需要使用代理服务器(如enter image description here)来使web组件工作(你已经加载像这样的Polymer,而不是iron-data-table)。

由于平庸polygit我花了一段时间才弄明白,如何将聚合物导入与iron-data-table结合起来。

所需的两种配置是iron-data-tablepolymer+:master

合并后,您的iron-data-table+Saulis+:master标记如下所示:

base

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

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

documentation(在谷歌浏览器中测试)

答案 1 :(得分:0)

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

  1. 下载包:
  2. bower i iron-data-table -S
    
    bower install --save PolymerElements/iron-ajax
    
    1. 创建引用这些包的html文件:
    2. <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文件:
      2. [
          {"name": {
            "title": "miss",
            "first": "donna",
            "last": "davis"
          }},
          {
            "name": {
              "title": "mr",
              "first": "samuel",
              "last": "kelley"
            }
          },
          {"name": {
            "title": "ms",
            "first": "katie",
            "last": "butler"
          }}
        ]