参考官方技术文档:http://jeecg-boot.mydoc.io/?t=345687
初始需求:如下图,当我修改产品名称的选项时,产品编码和产品规格的字段会根据我给出的数组自动改变。
1.首先我们需要将column
类型改为slot
才能自定义产品名称的可选列表以及添加同时修改功能。需要注意的是在技术文档中我们可以看到,当 type=slot
时所需的参数:
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
slotName | string | ✔️ | slot的名称 |
所以最终代码如下:
columns: [
{
title: '产品名称',
key: 'materialName',
type: FormTypes.slot,
slotName: 'materialName',
width: '20%',
},
{
title: '产品编码',
key: 'materialCode',
type: FormTypes.slot,
slotName: 'materialCode',
width: '20%',
},
{
title: '产品规格',
key: 'materialSpecs',
type: FormTypes.slot,
slotName: 'materialSpecs',
width: '60%',
},
2.然后再html
代码中添加对应的插槽:
<j-editable-table
:ref="tableName"
:loading="loading"
:columns="columns"
:dataSource="dataSource"
:maxHeight="300"
:rowNumber="true"
:rowSelection="true"
:actionButton="true"
>
<template v-slot:materialName="props">
<a-select
:default-value="props.text"
placeholder="请选择产品名称"
style="width: 100%"
show-search
@change="(value) => handleProChange(value, props.rowId)"
>
<a-select-option