Red*_*ed1 7 twitter-bootstrap bootstrap-4 vuejs2 bootstrap-vue
我在数据中有一个 bootstrap-vue 表(b-table),我想让它的 'Id' 值可以在以后的事件中访问,但我想从表渲染中隐藏它。
我以为我看到了一种通过将“Id”绑定到 row.key 或 row.index 或一些此类 b 表属性来实现此目的的方法,但我在任何地方都找不到。
所以我在字段定义中包含了列值,但我无法找到隐藏列的方法。
该表如下所示:
<b-table show-empty responsive striped hover small outlined :stacked="stack"
:items="DisplayViewData"
:fields="fields"
:sort-by.sync="sortBy"
:sort-desc.sync="sortDesc">
<template slot="select" slot-scope="data">
<b-form-checkbox v-model="data.item.IsSelected"/>
</template>
</b-table>
Run Code Online (Sandbox Code Playgroud)
字段定义如下:
fields: Array<any> = [
{key: 'Id',},
{key: 'LastName', sortable: true},
{key: 'FirstName', sortable: true},
etc.....
];
Run Code Online (Sandbox Code Playgroud)
但这意味着呈现了 Id 列。
有没有办法通过使“Id”列不可见或将 data.Id 值分配给其他一些 b 表行数据上下文来执行我想要的操作?
我对此的快速解决方案是这样的:
fields: Array<any> = [
{key: 'Id', thClass: 'd-none', tdClass: 'd-none' },
{key: 'LastName', sortable: true},
{key: 'FirstName', sortable: true},
etc.....
];
Run Code Online (Sandbox Code Playgroud)
所以对于 Id 使用thClass: 'd-none', tdClass: 'd-none'。
您所需要做的就是不将其包含fields
在定义中。项目行数据仍然存在,并且可以通过其他字段的作用域槽进行访问。
无需使用 CSS 类来隐藏该列。
要通过另一个字段作用域槽(例如槽)访问该值LastName
:
<b-table :fields-"fields" :items="items" ... >
<template slot="LastName" slot-scope="{ value, item }">
<!-- value is the field value -->
{{ value }}
<!-- item is the entire row object -->
<!--you can use it for actions on buttons, etc -->
<b-button @click="doSomthing(item.Id)">{{ item.Id }}</b-button>
</template>
</b-table>
Run Code Online (Sandbox Code Playgroud)
这类似于 Latovic 的回答,但使用 .d-none
fields: Array<any> = [
{key: 'Id', thClass: 'd-none', tdClass: 'd-none' },
{key: 'LastName', sortable: true},
{key: 'FirstName', sortable: true},
etc.....
];
Run Code Online (Sandbox Code Playgroud)
您想使用的原因.d-none
是它已经内置到 Bootstrap 4 中。
请参阅:https : //getbootstrap.com/docs/4.1/utilities/display/