现在我可以显示数据,但它们都在一个表格中。
我想要的是,每个代码都应该有一个表。像所有代码1应该在单独的表中,所有代码2都在单独的表中,依此类推。这是我显示表中的代码:
<template>
<div class="panel-con">
<ui-basic-table
ref="table"
:store="table.store"
:apiUrl="table.apiUrl"
:dataKey="table.dataKey"
:columns="table.columns"
:loadOnMount="true"
>
</ui-basic-table>
<template>
export default {
name: 'area-cost',
data() {
return {
}
},
computed:{
table(){
var table = {
apiUrl: this.$api.areacost.resource,
dataKey: this.$api.areacost.plural_key,
store:{
namespace:'AreaCost',
mutation:'set',
},
columns: [
{ name: 'area_id', label:'Code',width:40},
{ name: 'expected_cost', label: 'Target', width: 40 , format:'number' },
{ name: 'created_date',label:'Date',width:40, type:'text',format:'date'},
],
actions: [
{name: 'viewitem', label: '', icon: 'search', icon_color:
'primary',routelink:{}}
],
}
return table;
},
},
}
这有可能吗?
更新
<div class="panel-con">
<div v-for="(value, index) in areas" :key="index" >
{{ value.label }}
<ui-basic-table
ref="table"
:store="table.store" //tried :store="table.store[value.label]" or :store="table.store[index]"
:apiUrl="table.apiUrl"
:dataKey="table.dataKey"
:columns="table.columns"
:loadOnMount="true"
:searchparam="value.key"
>
</ui-basic-table>
<br/>
</div>
</div>
答案 0 :(得分:0)
不确定。创建一个返回唯一代码列表的计算器。为每个代码创建一个单独的商店。然后迭代:
<template>
<div v-for="code in uniqueCodes" :key="code">
<div class="panel-con">
<ui-basic-table
ref="table"
:store="table.store[code]"
:apiUrl="table.apiUrl"
:dataKey="table.dataKey"
:columns="table.columns"
:loadOnMount="true"
>
</ui-basic-table>
</div>
</div
<template>
我对数据和表的工作方式做了一些假设。即使这不太正确,我希望这个想法很清楚。
答案 1 :(得分:0)
将数据按代码拆分为单独的数组,例如:
new Vue({
el: "#app",
data: {
someData: [
{
code: 1,
name: 'test1'
},
{
code: 2,
name: 'test2'
},
{
code: 2,
name: 'test3'
},
{
code: 1,
name: 'test4'
},
{
code: 1,
name: 'test5'
},
{
code: 3,
name: 'test6'
}
]
},
computed: {
tables() {
let tabs = {};
this.someData.forEach((el, i) => (i = parseInt(el.code), tabs[i] ? tabs[i].push(el) : (tabs[i] = [el])));
return tabs;
}
}
})