Vaadin论坛上的TomiVirkki好心地给我发了一个使用计算绑定的简单示例。很明显,现在已经解释清楚了。。我想我得学点什么!谢谢Tomi
<vaadin-grid items="[[users.result]]">
<vaadin-grid-column width="50px" flex-grow="0">
<template class="header">#</template>
<template>
<iron-icon icon="[[_itemIcon(item)]]" style$="[[_itemIconStyles(item)]]"/>
</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">First Name</template>
<template>[[item.firstName]]</template>
</vaadin-grid-column>
<vaadin-grid-column>
<template class="header">Last Name</template>
<template>[[item.lastName]]</template>
</vaadin-grid-column>
</vaadin-grid>
</template>
<script>
window.addEventListener('WebComponentsReady', () => {
class XGrid extends Polymer.Element {
static get is() {
return 'x-grid';
}
_itemIcon(item) {
return item.firstName > 'N' ? 'arrow-upward' : 'arrow-downward';
}
_itemIconStyles(item) {
return `color: ${item.firstName > 'N' ? 'green' : 'red'}`;
}
}
customElements.define('x-grid', XGrid);