<s-table>、<a-table>接收后端数据

对于 中的 <template #bodyCell="{ column, record }"> :

html 复制代码
<s-table
	ref="table"
	:columns="columns"
	:data="loadData"
	:alert="options.alert.show"
	bordered
	:row-key="(record) => record.id"
	:tool-config="toolConfig"
	:row-selection="options.rowSelection"
>
	<template #operator class="table-operator">
		<a-space>
			<xn-batch-delete
				:selectedRowKeys="selectedRowKeys"
				@batchDelete="deleteBatchUserOrder"
			/>
		</a-space>
	</template>
	<template #bodyCell="{ column, record }">
		--------------------------------------------
		{{column.dataIndex}}
		--------------------------------------------
		{{record}}
		<!-- 操作列 -->
		<template v-if="column.dataIndex === 'action'">
			<a-space>
				<a @click="formRef.onOpen(record)" v-if="hasPerm('userOrderEdit')">编辑</a>
				<a-divider type="vertical" v-if="hasPerm(['userOrderEdit', 'userOrderDelete'], 'and')" />
				<a-popconfirm :title="$t('user.popconfirmDeleteUser')" @confirm="deleteUserOrder(record)">
					<a-button type="link" danger size="small" v-if="hasPerm('userOrderDelete')">删除</a-button>
				</a-popconfirm>
			</a-space>
		</template>
	</template>
</s-table>
javascript 复制代码
const columns = [
		{
      		title: detail,
			dataIndex: 'detail'
		},
		{
			title: change,
			dataIndex: 'change'
		},
		{
			title: reason,
			dataIndex: 'reason'
		},
	]

结果是:每一行的每一列(即每一个单元格,除了action操作列,因为它是看情况定有没有)都是以下数据样式:

复制代码
每行第一格:
-------------------------------------------- detail -------------------------------------------- { "id": "1737009774700765185", "userId": "1736567211313270786", "username": "xxx", "orderNo": "" }
每行第二格:
-------------------------------------------- change-------------------------------------------- { "id": "1737009774700765186", "userId": "1736567211313270787", "username": "xxxx", "orderNo": "" }
每行第三格:
-------------------------------------------- reason-------------------------------------------- { "id": "1737009774700765187", "userId": "1736567211313270788", "username": "xxxxx", "orderNo": "" }

如果将 {{column.dataIndex}} 改为 {{column}} ,则输出的不只是 dataIndex,还有 title,即 detail 改为:{ "title": "detail", "dataIndex": "detail" } 。

column 为定义的列:

:columns="columns"

const columns = [

{

title: 用户名,

dataIndex: 'username'

},

]

并不是实体类中所有的属性名称,而是 columns 中定义的数据;

record 为集合中每一条数据,相当于一个实体类中所有的数据;

所以遍历 column 即遍历所有的列头;

遍历 record 就是遍历集合中的每条数据。

所以 columns 可以自定义,但是 record 是查询出来的数据,包括属性名,每一条记录eg:{ "id": "1737009774700765185", "userId": "1736567211313270786", "username": "xxx" }

想要在antd中 中获得每一行的索引:

<template #bodyCell="{column, record, index}">,一直以来都是只使用<template #bodyCell="{column, record}">,column为列属性,record为每行数据记录,而index为每行索引,从0开始,想要获得直接使用ndex即可,不同行index值不同,0、1、2...

获取 中的哪一列的哪个属性:

html 复制代码
<a-table :data-source="selectData" :columns="columns">
<template #bodyCell="{column, record, index}">
</template>
</a-table>
javascript 复制代码
const columns = [
    {
       title: '名称',
       dataIndex: 'name',
       align: 'center',
       width: '60%'
    },
    {
       title: '场景',
       dataIndex: 'sceneSeries',
       align: 'center',
       width: '40%'
    }
] 
const formData = ref({})     
formData.value.sceneList = selectData.value
console.log(selectData.value[index].name)    // 第index行的name
console.log(selectData.value[index].sceneSeries)    // 第index行的sceneSeries

后台接收:

java 复制代码
	private List<VideoSceneParam> sceneList;
    @Setter
    @Getter
    public class VideoSceneParam {
        private String name;
        private String sceneSeries;
    } 
相关推荐
凤凰战士芭比Q9 小时前
部署我的世界-java版服务器-frp内网穿透
java·服务器
小肖爱笑不爱笑9 小时前
2025/11/5 IO流(字节流、字符流、字节缓冲流、字符缓冲流) 计算机存储规则(ASCII、GBK、Unicode)
java·开发语言·算法
CodeCraft Studio9 小时前
PPT处理控件Aspose.Slides教程:使用Java将PowerPoint笔记导出为PDF
java·笔记·pdf·powerpoint·aspose·ppt转pdf·java将ppt导出pdf
手握风云-9 小时前
Java 数据结构第二十八期:反射、枚举以及 lambda 表达式
java·开发语言
ᐇ9599 小时前
Java Vector集合全面解析:线程安全的动态数组
java·开发语言
毕设源码-朱学姐9 小时前
【开题答辩全过程】以 广州网红点打卡介绍网站为例,包含答辩的问题和答案
java·eclipse
程序定小飞10 小时前
基于springboot的web的音乐网站开发与设计
java·前端·数据库·vue.js·spring boot·后端·spring
百锦再10 小时前
第1章 Rust语言概述
java·开发语言·人工智能·python·rust·go·1024程序员节
武昌库里写JAVA10 小时前
element-ui 2.x 及 vxe-table 2.x 使用 css 定制主题
java·vue.js·spring boot·sql·学习
JavaGuide11 小时前
OPPO 后端校招面试,过于简单了!
java·后端