Iron-data-table 无法从数据绑定中填充数据
Iron-data-table fails to populate data from databinding
The following code taken from this demo works in my app:
https://saulis.github.io/iron-data-table/demo/index.html
<template is="dom-bind">
<iron-ajax
url="https://saulis.github.io/iron-data-table/demo/users.json"
last-response="{{users}}"
auto>
</iron-ajax>
<iron-data-table id="items"
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>
但是当我将数据源从 iron-ajax
调用更改为内部数据绑定 {{items}}
时,它不起作用。
items-list.html
<template is="dom-bind">
<iron-data-table id="items"
selection-enabled
data-source="[[items]]">
<data-table-column name="Comment" width="50px" flex="0">
<template>[[item.comment]]</template>
</data-table-column>
<data-table-column name="Total">
<template>[[item.total]]</template>
</data-table-column>
<data-table-column name="Merchant">
<template>[[item.merchant]]</template>
</data-table-column>
</iron-data-table>
</template>
我希望 table 填充数据。相反,table 和列 headers 呈现但数据不填充 table.
几点:
我正在使用 Firebase 来存储数据。 polymerfire/firebase-query
元素(在所示元素的 parent 数据绑定元素中)获取 {{items}}
数据。
我应该朝哪个方向尝试解决这个问题?
编辑
下面描述了我对 items
变量的设置方式和内容:
我的Firebase里面的数据结构如下。
https://console.firebase.google.com/project/my-app/database/data
my-app
|
- users
|
- userid-123
|
- nodeid-abc
| |- comment: "foo"
| |- merchant: "bar"
| |- date: "2016-07-02"
| |- total: 123
- nodeid-xyx
|- comment: "baz"
|- merchant: "bat"
|- date: "2016-07-15"
|- total: 999
我通过 Polymerfire firebase-query
元素中的 parent 元素将数据提取到我的应用程序中。
overview-page.html
<firebase-query
id="query"
app-name="my-app"
path="/users/[[user.uid]]"
data="{{items}}">
</firebase-query>
<items-list id="list"
items="[[items]]"
filters="[[filters]]">
</items-list>
我知道 {{items}}
数据正在进入 list-items
元素,因为我设置了一个按钮来将数据记录到控制台。
items-list.html
<button on-tap="show">Show</button>
show: function() {
console.log('items', this.items);
},
当我按下 Show 按钮时,控制台记录以下内容:
console.log
items
0: Object
$key: "nodeid-abc"
comment: "foo"
merchant: "bar"
date: "2016-07-02"
total: 123
1: Object
$key: "nodeid-xyx"
comment: "baz"
merchant: "bat"
date: "2016-07-15"
total: 999
有趣的是,当我为工作代码示例记录相同的信息时:
show: function(){
console.log('users', this.users);
}
我得到:
console.log
users undefined
算了吧。显然,有些事情我不明白。看起来 {{items}}
数据绑定在 iron-data-table
呈现之后注册,并且由于某种原因,数据绑定在 iron-list
元素中注册后未在 iron-data-table
中更新。
编辑2
这是 items-list
元素的完整 dom-module
定义。
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-data-table/iron-data-table.html">
<link rel="import" href="../bower_components/iron-data-table/default-styles.html">
<dom-module id="items-list">
<template>
<button on-tap="show">Show</button>
<template is="dom-bind">
<iron-data-table items="[[items]]">
<data-table-column name="Comment">
<template>[[item.comment]]</template>
</data-table-column>
<data-table-column name="Merchant">
<template>[[item.merchant]]</template>
</data-table-column>
</iron-data-table>
</template>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'items-list',
properties: {
items: {
type: Array,
notify: true,
},
},
show: function() {
console.log('items', this.items);
},
});
})();
</script>
</dom-module>
您需要删除额外的 <template is="dom-bind">
元素,它将 <iron-data-table>
封装在一个单独的绑定范围中。 dom-bind
不是必需的,因为您有来自 dom-module
的绑定范围
我假设您从演示示例中复制了 dom-bind
元素,这里需要它们,因为 <iron-data-table>
周围没有自定义元素。您可以在此处查看更多信息:https://www.polymer-project.org/1.0/docs/devguide/templates#dom-bind
The following code taken from this demo works in my app:
https://saulis.github.io/iron-data-table/demo/index.html<template is="dom-bind">
<iron-ajax
url="https://saulis.github.io/iron-data-table/demo/users.json"
last-response="{{users}}"
auto>
</iron-ajax>
<iron-data-table id="items"
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>
但是当我将数据源从 iron-ajax
调用更改为内部数据绑定 {{items}}
时,它不起作用。
<template is="dom-bind">
<iron-data-table id="items"
selection-enabled
data-source="[[items]]">
<data-table-column name="Comment" width="50px" flex="0">
<template>[[item.comment]]</template>
</data-table-column>
<data-table-column name="Total">
<template>[[item.total]]</template>
</data-table-column>
<data-table-column name="Merchant">
<template>[[item.merchant]]</template>
</data-table-column>
</iron-data-table>
</template>
我希望 table 填充数据。相反,table 和列 headers 呈现但数据不填充 table.
几点:
我正在使用 Firebase 来存储数据。 polymerfire/firebase-query
元素(在所示元素的 parent 数据绑定元素中)获取 {{items}}
数据。
我应该朝哪个方向尝试解决这个问题?
编辑
下面描述了我对 items
变量的设置方式和内容:
我的Firebase里面的数据结构如下。
https://console.firebase.google.com/project/my-app/database/datamy-app
|
- users
|
- userid-123
|
- nodeid-abc
| |- comment: "foo"
| |- merchant: "bar"
| |- date: "2016-07-02"
| |- total: 123
- nodeid-xyx
|- comment: "baz"
|- merchant: "bat"
|- date: "2016-07-15"
|- total: 999
我通过 Polymerfire firebase-query
元素中的 parent 元素将数据提取到我的应用程序中。
<firebase-query
id="query"
app-name="my-app"
path="/users/[[user.uid]]"
data="{{items}}">
</firebase-query>
<items-list id="list"
items="[[items]]"
filters="[[filters]]">
</items-list>
我知道 {{items}}
数据正在进入 list-items
元素,因为我设置了一个按钮来将数据记录到控制台。
<button on-tap="show">Show</button>
show: function() {
console.log('items', this.items);
},
当我按下 Show 按钮时,控制台记录以下内容:
console.logitems
0: Object
$key: "nodeid-abc"
comment: "foo"
merchant: "bar"
date: "2016-07-02"
total: 123
1: Object
$key: "nodeid-xyx"
comment: "baz"
merchant: "bat"
date: "2016-07-15"
total: 999
有趣的是,当我为工作代码示例记录相同的信息时:
show: function(){
console.log('users', this.users);
}
我得到:
console.logusers undefined
算了吧。显然,有些事情我不明白。看起来 {{items}}
数据绑定在 iron-data-table
呈现之后注册,并且由于某种原因,数据绑定在 iron-list
元素中注册后未在 iron-data-table
中更新。
编辑2
这是 items-list
元素的完整 dom-module
定义。
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-data-table/iron-data-table.html">
<link rel="import" href="../bower_components/iron-data-table/default-styles.html">
<dom-module id="items-list">
<template>
<button on-tap="show">Show</button>
<template is="dom-bind">
<iron-data-table items="[[items]]">
<data-table-column name="Comment">
<template>[[item.comment]]</template>
</data-table-column>
<data-table-column name="Merchant">
<template>[[item.merchant]]</template>
</data-table-column>
</iron-data-table>
</template>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'items-list',
properties: {
items: {
type: Array,
notify: true,
},
},
show: function() {
console.log('items', this.items);
},
});
})();
</script>
</dom-module>
您需要删除额外的 <template is="dom-bind">
元素,它将 <iron-data-table>
封装在一个单独的绑定范围中。 dom-bind
不是必需的,因为您有来自 dom-module
我假设您从演示示例中复制了 dom-bind
元素,这里需要它们,因为 <iron-data-table>
周围没有自定义元素。您可以在此处查看更多信息:https://www.polymer-project.org/1.0/docs/devguide/templates#dom-bind