为了完整起见,接受的答案中的代码如下:
http://plnkr.co/edit/VWIAvWAnuf2aiCjJjCdI?p=preview
<base href="https://polygit.org/polymer+:master/iron-data-table+Saulis+: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 rel="import" href="iron-data-table/iron-data-table.html">
<dom-module id="content-el">
<template>
<style></style>
<iron-ajax
auto
url="https://saulis.github.io/iron-data-table/demo/users.json"
last-response="{{users}}">
</iron-ajax>
<iron-data-table
data-source="[[dataSource]]">
<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: 'content-el',
properties: {
users: Array,
dataSource: Function
},
observers: ['_usersChanged(users)'],
_usersChanged: function(users) {
this.dataSource = function(params, callback) {
var filteredUsers = users.results.filter(function(item) {
return item.user.name.first.length > 6;
});
callback(filteredUsers, filteredUsers.length);
};
}
});
})();
</script>
</dom-module>