简体   繁体   English

聚合物1.0中的dom-repeat里面的内容?

[英]content inside dom-repeat in Polymer 1.0?

My problem is that I can´t find the way to bind data using <content> tag. 我的问题是我找不到使用<content>标签绑定数据的方法。 I want to make a table element in which one you only pass an array of titles and array of objects representing data to use. 我想创建一个表元素,其中只传递一个标题数组和表示要使用的数据的对象数组。

My code to show data is as follows: 我显示数据的代码如下:

<template is="dom-repeat" items="{{rows}}">
    <td>{{item.Id}}</td><td>{{item.Descripcion}}</td>
</template>

But if I use this way, my table element only will work when the rows has an Id or Descripcion properties. 但是如果我使用这种方式,只有当行具有Id或Descripcion属性时,我的表元素才会起作用。
I want to do something like this: 我想做这样的事情:

<template is="dom-repeat" items="{{rows}}">
    <content></content><!--dynamic item-->
</template>

So, when I call my table element should be something like this: 所以,当我调用我的table元素应该是这样的:

<my-table titles="[arrayOfTitles]" rows="[arrayOfRows]">
    <td>{{item.propertyOne}}</td><td>{{item.propertyTwo}}</td><td>{{item.propertyN}}</td>
</my-table>

In which <td></td> will have the data to represent inside it. 其中<td></td>将有数据在其中表示。
This sounds crazy? 这听起来很疯狂? It is possible to do? 有可能吗?

I have tried using getDistributedNodes function but I don´t know how to use it to do what I want. 我曾尝试使用getDistributedNodes函数,但我不知道如何使用它来做我想要的。 Sorry for my English. 对不起我的英语不好。 Thanks! 谢谢! Any help will be great! 任何帮助都会很棒!

Edit 编辑

When I use my element looks as follows: 当我使用我的元素时,如下所示:

<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>

Now, the problem is how to use objects more complexes, when I use Objects or Arrays they displays like this: 现在,问题是如何使用更复杂的对象,当我使用对象或数组时,它们显示如下: 在此输入图像描述
As you can see, when I use objects or arrays displays [object Object], any idea of how to construct my table declaration to indicate if it has objects? 正如你所看到的,当我使用对象或数组显示[object Object]时,是否知道如何构造我的表声明以指示它是否有对象? I want to make something like this: 我想做这样的事情: 在此输入图像描述

My <tbody> is like @so_confused_ said: 我的<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>
        <tbody>
            <template is="dom-repeat" items="{{visibleRows}}" id="tableRow" as="row">
                <tr on-tap="rowSelected" class$="{{getClass(row.active)}}" style="cursor:cell;">
                    <template is="dom-repeat" items="{{headers}}" id="tableRow2" as="column">
                        <template is="dom-if" if="{{areEquals(column.type, 'object')}}">
                            <td>{{getObjectValue(column,row)}}</td>
                        </template>
                        <template is="dom-if" if="{{areEquals(column.type, 'array')}}">
                            <td>
                                <template is="dom-repeat" items="{{getDataArray(column,row)}}">
                                    <li>{{getArrayValue(item,column)}}</li>
                                </template>
                            </td>
                        </template>
                        <template is="dom-if" if="{{areEquals(column.type, 'text')}}">
                            <td>{{getValue(column,row)}}</td>
                        </template>
                    </template>
                </tr>
            </template>
        </tbody>

Depending on the type of column you call the corresponding function. 根据列的类型,您可以调用相应的函数。

If you're not rendering with the same key all the time, can you just use your input as an array of arrays? 如果您不是一直使用相同的键进行渲染,那么您可以将输入用作数组数组吗?

if you have an array: arr = [["one","two","three","four"],["one","two"],["one","two","three"]]; 如果你有一个数组: arr = [["one","two","three","four"],["one","two"],["one","two","three"]]; then you can render rows of different lengths by iterating over the nested array 然后,您可以通过迭代嵌套数组来呈现不同长度的行

<template is="dom-repeat" items="{{arr}}">
  <tr>
    <template is="dom-repeat" items="{{item}}>
      <td>{{item}}</td>
    </template>
  </tr>
</template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM