javascript - 如何在 Vue 的 ant-table 中显示数据?
问题描述
我是 vue.js 和 ant-design 组件的新手。我有一个对象数组,我必须在表格中显示哪些字段。我的问题是我无法在每一行中获取特定字段的值(== 我的数据源数组中的索引)。我该怎么做?谢谢
代码:
<a-table
:columns='columns'
:pagination='false'
:data-source='tableDataSource'
class='table table-small'
>
// Here somehow i have to get my field from current index in my data-source
<template slot='clientName' slot-scope='props'>
<a :href='props.client.id'>
{{props.client.firstName}}
</a>
</template>
<a-select
slot='status'
slot-scope='status'
class='status-select'
@change="event => handleChangeStatus(event, 'booking')"
:default-value='status'
:key='index'
name='status'
>
<a-select-option
v-for='item in bookingClassesStatus'
:key='item.id'
:value='item.value'
>
{{ item.text }}
</a-select-option>
</a-select>
</a-table>
解决方案
我解决了这个!
编辑列:
...
// enable custom rendering
{
title: 'Client name',
dataIndex: 'clientName',
key: 'client',
scopedSlots: { customRender: 'clientName' },
},
...
<a-table :columns='columns'
:pagination='false'
:data-source='tableDataSource'
rowKey='id'
class='table table-small'>
<template slot='clientName' slot-scope="text, record">
<a :href="'/admin/clients/' + record.client.id">{{record.client.firstName + " " + record.client.lastName}}</a>
</template>
<a-select slot='status' slot-scope='status' class='status-select'
@change="event => handleChangeStatus(event, 'booking')"
:default-value='status'
:key='index'
name='status'>
<a-select-option v-for='item in bookingClassesStatus'
:key='item.id'
:value='item.value'>{{ item.text }}
</a-select-option>
</a-select>
</a-table>
据我了解,slot-scope 获取当前数据源项并操作当前实例,提供对我对象的所有字段的访问。可能我弄错了。
推荐阅读
- django - 聚合以及额外的值
- paypal - Paypal REST API - 检测到重复的发票 ID
- asp.net-web-api-filters - web api 操作过滤器不调用,为什么?
- sql - 查找 SQL Server 2008 中用户的日期范围之间的差距
- python - 更改列表中列的大小写
- wordpress - 将项目从本地计算机上传到 Azure DevOps 时遇到问题
- angular - Angular 6 - 选择名称时显示动态div
- python - 如何从 .txt 文件中绘制图形(y 轴设置)?
- angular - 自定义、用户特定文档字段的 Firestore 索引
- android - 如何在 Google Play 上收到有关一次性产品购买的通知