polymer实现动态数据并且带有表格合并

析构季风
• 阅读 1823

最近接到一个需求,就是要做一个页面放个表格来显示数据,并且数据条数是动态并且规定格式且带合并的;
首先看效果图:

polymer实现动态数据并且带有表格合并

1. 服务返回的数据结构:

data: {
    type: Array,
    value: [{
        "designation": "001",
        "rows": [{
            "manufacturerName": "广州",
            "manufacturerId": 100,
            "myProductOffers":[{"a": "供应商","b": "期/现货",...}],
            "todayDealPrice": [{"a": "供应商","b": "期/现货",...}],
            "otherProductOffers":[{"a": "供应商","b": "期/现货",...}],
        }]

2. 页面代码是这样子的:

 <tbody>
         <template is="dom-repeat" items="[[data]]" as="data">
             <template is="dom-repeat" items="[[data.rows]]" as="rows" index-as="rowsIndex">
                 <template is="dom-repeat" items="[[rows.myProductOffers]]" as="myProductOffers" index-as="customerIndex">
                     <tr>
                         <template is="dom-if" if="[[_isFirstRow(rowsIndex)]]">
                             <td rowspan$="[[_getDataLength(data)]]">[[data.designation]]</td>
                         </template>
                         <td rowspan$="[[_getRowsLength(rows)]]">[[rows.manufacturerName]]</td>
                         <td>报价</td>
                         <td>[[myProductOffers.a]]</td>
                         <td>[[myProductOffers.b]]</td>
                         <td>[[myProductOffers.c]]</td>
                         <td>[[myProductOffers.d]]</td>
                         <td>[[myProductOffers.e]]</td>
                         <td>[[myProductOffers.f]]</td>
                         <td>[[myProductOffers.g]]</td>
                         <td>[[myProductOffers.h]]</td>
                         <td>[[myProductOffers.i]]</td>
                         <td>[[myProductOffers.j]]</td>
                         <td>[[myProductOffers.k]]</td>
                         <td>[[myProductOffers.l]]</td>
                     </tr>
                 </template>

                 <template is="dom-repeat" items="[[rows.todayDealPrice]]" as="todayDealPrice" index-as="todayIndex">
                     <tr>
                         <template is="dom-if" if="[[_isFirstRow(todayIndex)]]">
                            <td rowspan$="[[_getArrayLength(rows.todayDealPrice)]]">当天成交价</td>
                         </template>
                         <td>[[todayDealPrice.a]]</td>
                         <td>[[todayDealPrice.b]]</td>
                         <td>[[todayDealPrice.c]]</td>
                         <td>[[todayDealPrice.d]]</td>
                         <td>[[todayDealPrice.e]]</td>
                         <td>[[todayDealPrice.f]]</td>
                         <td>[[todayDealPrice.g]]</td>
                         <td>[[todayDealPrice.h]]</td>
                         <td>[[todayDealPrice.i]]</td>
                         <td>[[todayDealPrice.j]]</td>
                         <td>[[todayDealPrice.k]]</td>
                         <td>[[todayDealPrice.l]]</td>
                     </tr>
                 </template>
                 <template is="dom-repeat" items="[[rows.otherProductOffers]]" as="otherProductOffers" index-as="otherIndex">
                     <tr>
                         <template is="dom-if" if="[[_isFirstRow(otherIndex)]]">
                             <td rowspan$="[[_getArrayLength(rows.otherProductOffers)]]">当天其他报价</td>
                         </template>
                         <td>[[otherProductOffers.a]]</td>
                         <td>[[otherProductOffers.b]]</td>
                         <td>[[otherProductOffers.c]]</td>
                         <td>[[otherProductOffers.d]]</td>
                         <td>[[otherProductOffers.e]]</td>
                         <td>[[otherProductOffers.f]]</td>
                         <td>[[otherProductOffers.g]]</td>
                         <td>[[otherProductOffers.h]]</td>
                         <td>[[otherProductOffers.i]]</td>
                         <td>[[otherProductOffers.j]]</td>
                         <td>[[otherProductOffers.k]]</td>
                         <td>[[otherProductOffers.l]]</td>
                     </tr>
                 </template>
             </template>
         </template>
    </tbody>

这里要注意的是每一层循环的index,利用这个index来判断合并的项是第一个的时候显示就可以了

3. 对应的js代码:

_getDataLength: function (data) {
    let length = 0;
    data.rows.forEach(e=>{
        length += e.myProductOffers.length
        length += e.todayDealPrice.length  
        length += e.otherProductOffers.length
    })

    return length
},
_getRowsLength: function (rows) {
    let length = rows.myProductOffers.length+ rows.todayDealPrice.length+rows.otherProductOffers.length;
    return length
},
_getArrayLength: function (rows) {
    return rows.length
},
_isFirstRow:function (index) {
    return index === 0
}
点赞
收藏
评论区
推荐文章
blmius blmius
4年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
美凌格栋栋酱 美凌格栋栋酱
10个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
Wesley13 Wesley13
4年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
皕杰报表(关于日期时间时分秒显示不出来)
在使用皕杰报表设计器时,数据据里面是日期型,但当你web预览时候,发现有日期时间类型的数据时分秒显示不出来,只有年月日能显示出来,时分秒显示为0:00:00。1.可以使用tochar解决,数据集用selecttochar(flowdate,"yyyyMMddHH:mm:ss")fromtablename2.也可以把数据库日期类型date改成timestamp
Wesley13 Wesley13
4年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Stella981 Stella981
4年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Easter79 Easter79
4年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
4年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Easter79 Easter79
4年前
SpringBoot整合Redis乱码原因及解决方案
问题描述:springboot使用springdataredis存储数据时乱码rediskey/value出现\\xAC\\xED\\x00\\x05t\\x00\\x05问题分析:查看RedisTemplate类!(https://oscimg.oschina.net/oscnet/0a85565fa
Wesley13 Wesley13
4年前
Java日期时间API系列36
  十二时辰,古代劳动人民把一昼夜划分成十二个时段,每一个时段叫一个时辰。二十四小时和十二时辰对照表:时辰时间24时制子时深夜11:00凌晨01:0023:0001:00丑时上午01:00上午03:0001:0003:00寅时上午03:00上午0