【发布时间】:2016-02-11 15:21:20
【问题描述】:
我正在尝试创建一个简单的 Polymer 组件,该组件从数据数组中呈现一个表。所述组件的预期用途示例如下:
<my-table data="{{someArray}}">
<my-column header="Id"><template>{{item.id}}</template></my-column>
<my-column header="Name"><template>{{item.name}}</template></my-column>
</my-table>
渲染应该是这样的:
然而,在创建一个半工作原型时,事情变得复杂了。原型可以在这里找到:http://jsbin.com/sirutusupu/edit?html,console,output。 免责声明:除非您下载它并通过本地http-server 运行它,否则它不起作用。
我的第一个问题:为什么原型只能通过本地http-server工作?
我的第二个问题:在本地运行时,当我用dom-bind 包装自定义元素时,它也停止工作。本地代码(也不起作用):
<template is="dom-bind">
<my-table>
<my-column header="Id"><template>{{item.id}}</template></my-column>
<my-column header="Name"><template>{{item.name}}</template></my-column>
</my-table>
</template>
我的第三个问题:使用函数格式化输出不起作用。考虑这个扩展示例:
<script>
function concat(a, b) {
return a + "-" + b;
}
</script>
<my-table>
<my-column header="Id"><template>{{item.id}}</template></my-column>
<my-column header="Name"><template>{{item.name}}</template></my-column>
<my-column header="Computed"><template>{{concat(item.id, item.name)}}</template></my-column>
</my-table>
产生的错误是polymer.html:1660 [undefined::_annotatedComputationEffect]: compute method 'concat' not defined。
有没有办法在不定义计算绑定的情况下解决这个问题?否则无法自定义单元格值的格式。
【问题讨论】:
标签: javascript html templates polymer polymer-1.0