【发布时间】:2015-10-23 17:01:57
【问题描述】:
我的问题是我找不到使用<content> 标签绑定数据的方法。我想制作一个表格元素,您只需在其中传递一个标题数组和表示要使用的数据的对象数组。
我显示数据的代码如下:
<template is="dom-repeat" items="{{rows}}">
<td>{{item.Id}}</td><td>{{item.Descripcion}}</td>
</template>
但如果我使用这种方式,我的表格元素只有在行具有 Id 或 Descriptcion 属性时才会起作用。
我想做这样的事情:
<template is="dom-repeat" items="{{rows}}">
<content></content><!--dynamic item-->
</template>
所以,当我调用我的表格元素时,应该是这样的:
<my-table titles="[arrayOfTitles]" rows="[arrayOfRows]">
<td>{{item.propertyOne}}</td><td>{{item.propertyTwo}}</td><td>{{item.propertyN}}</td>
</my-table>
<td></td> 将在其中包含要表示的数据。
这听起来很疯狂?有可能吗?
我尝试过使用getDistributedNodes 函数,但我不知道如何使用它来做我想做的事。对不起我的英语不好。谢谢!任何帮助都会很棒!
编辑
当我使用我的元素时,如下所示:
<my-table api-url="../../api/feeApi"
headers='[{"title":"Id"},{"title":"Descripción"},{"title":"Abreviatura"},{"title":"Tipo"},{"title":"Monto($)"},{"title":"Cobrar a"}]'
keys='["Id","Descripcion","ShortName","FeeType","Monto","NivelesEscolares"]'
number-visible-rows="10">
</my-table>
现在,问题是如何使用更复杂的对象,当我使用对象或数组时,它们显示如下:
如您所见,当我使用对象或数组显示 [object Object] 时,您知道如何构造我的表声明以指示它是否有对象吗?我想做这样的事情:
我的<tbody>就像@so_confused_说的:
<tbody>
<template is="dom-repeat" items="{{visibleRows}}" id="tableRow">
<tr on-tap="rowSelected" class$="{{getClass(item.active)}}">
<template is="dom-repeat" items="{{item.row}}" id="tableData">
<td>{{item}}</td>
</template>
</tr>
</template>
</tbody>
【问题讨论】:
-
您可以尝试获取 'item' 的值并绑定到该值
-
我该怎么做@GlennVandeuren?
标签: javascript dom data-binding polymer