json - 如何在表vuejs中显示json
问题描述
如何显示以下 json 数据?我有这样的 json 数据,并且想在表格中显示它,我使用 vue-bostrapt 。以前我试过这样,但它并不完美。
这是我的 json
[
{
"id":"1",
"name": "KINTIL",
"desc": "Kintil is good",
"location": [
{
"prov": "Jawa Barat",
"city": "Bandung"
},
{
"prov": "Banten",
"city": "Tanggerang"
}
],
"applied": [
{
"item_name": "galian"
},
{
"item_name": "timbunan"
}
],
"exception": [
{
"ex_name": "F001",
"ex_value": "001001"
},
{
"ex_name": "M001",
"ex_value": "002002"
}
]
}
]
和这个 html
<b-table class="table spacing-table" style="font-size: 13px;" show-empty
:items="inovasi" :fields="fields" :current-page="currentPage" :per-page="0" :filter="filter" >
</b-table>
这是我的脚本
import json from "../static/data.json";
export default {
name: 'tes',
data() {
return {
inovasi:[],
filter: null,
fields: [
{
key: 'id',
label: 'id',
sortable: true
},
{
key: 'name',
label: 'name',
sortable: true
},
{
key: 'location',
label: 'location',
sortable: true
},
{
key: 'applied',
label: 'applied',
sortable: true
},
{ key: 'actions', label: 'Doc' }
],
currentPage: 0,
perPage: 5,
totalItems: 0
}
},
mounted() {
this.inovasi = json;
},
computed:{
},
methods: {
}
}
如何显示位置和应用,成单行表?提前感谢那些回答的人:)
谢谢
解决方案
您可以使用格式化程序来做到这一点
fields: [
{
key: 'id',
label: 'id',
sortable: true
},
{
key: 'name',
label: 'name',
sortable: true
},
{
key: 'location',
label: 'location',
sortable: true,
formatter: (value, key, item) => {
return value.map(x => 'prov: ' + x.prov + ' city:' + x.city).join(", ")
}
},
{
key: 'applied',
label: 'applied',
sortable: true,
formatter: (value, key, item) => {
return value.map(x => x.item_name).join(", ")
}
},
{ key: 'actions', label: 'Doc' }
],
它将为位置列显示此:prov: Jawa Barat city:Bandung, prov: Banten city:Tanggerang
对于应用列,它将显示:galian, timbunan
推荐阅读
- excel - 设置身份验证 XMLHTTP 导出 HTML
- python - 向 aiohttp WSGI 处理程序添加路由
- scala - 两个流之间的Scala Flink Join不起作用
- android - NativeScript ./gradlew 失败,退出代码为 1
- javascript - 为什么我得到两个橙子和 abc arrys 的相同输出?
- spring - 尽管我使用的是 spring taglib,但在 jsp 中未定义 Spring tag(form : form)。为什么?
- azure - EXE 在本地 Docker 容器中运行,但在 Azure 上
- android - 错误崩溃原因:空指针取消引用 Unity/firebase
- java - 在JAVA中获取树形图中唯一值的所有键
- apache-spark - 如何在spark sql case/when语句中为多个列分配值