<el-table v-loading=loading :data=directionList > <el-table-column label=流出区域id align=center prop=outAreaId /> <el-table-column label=流出区域 align=center prop=areaName /> 怎么将这两个不同表的参数关联起来并展示时两个参数是成双展示
时间: 2024-02-21 16:59:17 浏览: 24
如果这两个参数来自不同的表,你需要先将这两个表关联起来,然后再使用插槽来展示它们。假设这两个表的数据都已经获取到了,你可以使用 JavaScript 来将它们关联起来。例如:
```js
const directionList = [
{ outAreaId: 1, inAreaId: 2 },
{ outAreaId: 3, inAreaId: 4 }
];
const areaList = [
{ id: 1, name: "区域1" },
{ id: 2, name: "区域2" },
{ id: 3, name: "区域3" },
{ id: 4, name: "区域4" }
];
const mergedList = directionList.map(direction => {
const outArea = areaList.find(area => area.id === direction.outAreaId);
const inArea = areaList.find(area => area.id === direction.inAreaId);
return {
outAreaId: direction.outAreaId,
outAreaName: outArea.name,
inAreaId: direction.inAreaId,
inAreaName: inArea.name
};
});
```
在上面的代码中,我们使用了 Array.prototype.map() 方法来遍历 directionList 数组,并在每个元素中查找对应的 outArea 和 inArea,然后将它们合并成一个新的对象。这样,我们就得到了一个 mergedList 数组,其中每个元素都包含了 outAreaId、outAreaName、inAreaId 和 inAreaName 四个参数。
接下来,我们可以在 el-table-column 中使用插槽来展示这些参数。例如:
```html
<el-table v-loading="loading" :data="mergedList">
<el-table-column label="流出区域" align="center">
<template slot-scope="{ row }">
{{ row.outAreaId }} - {{ row.outAreaName }}
</template>
</el-table-column>
<el-table-column label="流入区域" align="center">
<template slot-scope="{ row }">
{{ row.inAreaId }} - {{ row.inAreaName }}
</template>
</el-table-column>
</el-table>
```
在这个例子中,我们使用了两个 el-table-column 来分别展示流出区域和流入区域,然后在每个 el-table-column 中使用了 scoped slot 来定义一个模板,将 outAreaId、outAreaName、inAreaId 和 inAreaName 组合在一起展示。这样,就可以将这两个不同表的参数关联起来并展示时两个参数是成双展示了。