后端返回数据动态标题拼接静态标题,拼接数据

在这里插入图片描述
前两个标题是动态。后两个静态。最后一个是可编辑

1.首先看下后端返回数据结构、

data下一条数据里包含table标题跟一组数据。

<el-table :data="stockList" border style="width: 100%;">
                <el-table-column :prop="item.value" :label="item.name" v-for="(item,index) in tableColumnList" :key="index">    
                </el-table-column>
                <el-table-column label="增加可用库">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row"></el-input>
                    </template>
                </el-table-column>
            </el-table>

逻辑拼接

getCommodityState(val) {
                getCommodityState(val).then(res => {
                    console.info(res.data)
                    let stockList = res.data;
                    if(stockList.length){
                        this.tableColumnList = []
                        stockList[0].list.forEach(column=>{
                            this.tableColumnList.push({
                                name: column.formatName,
                                value: `formatKey${column.formatId}`
                            })
                        })
                        this.tableColumnList = [
                            ...this.tableColumnList,
                            ...this.defaultTableColumnList
                        ]
                    }
                    let formatStockList = []
                    stockList.forEach(item => {
                        let format = item
                        item.list.forEach(fmt=>{
                            format[`formatKey${fmt.formatId}`] = fmt.formatValue
                        })
                        delete format.list
                        formatStockList.push(format)
                    });
                    this.stockList = formatStockList
                }).catch(err => {
                    console.log(err)
                })
            }

1.新数组拼接标题,循环一次取出动态标题。拼接上静态写死标题
2.再拿参数对应ID作为标识拼接字符串。
3.取到数据删除渲染

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值