Vue.js 格式化程序列-引导vue-VueJS

Vue.js 格式化程序列-引导vue-VueJS,vue.js,bootstrap-vue,Vue.js,Bootstrap Vue,我需要对from和to列应用格式化程序,以便将它们识别为表中显示的值、它们的描述而不是它们的代码 <b-table id="my-table" hover striped small outlined :items="items" :fields="fields" class="mt-0 mb-0"> <template slot="actions" slot-scope="data"> <b-button variant="info" @c

我需要对from和to列应用格式化程序,以便将它们识别为表中显示的值、它们的描述而不是它们的代码

<b-table id="my-table" hover striped small outlined :items="items" :fields="fields" class="mt-0 mb-0">
    <template slot="actions" slot-scope="data">
        <b-button variant="info" @click="viewMessage(data.item)" class="mr-2" size="sm">
            <i class="fa fa-envelope-open"> View</i>
        </b-button>
    </template>
</b-table>

items: [
    { date: '01/01/2008', from: '1', to: '2', city: 'Paris' },
    { date: '06/03/2018', from: '3', to: '1', city: 'New York' },
    { date: '05/06/2012', from: '3', to: '2', city: 'Tokyo' },
    { date: '07/08/2019', from: '2', to: '3', city: 'Paris' }
]

fields: [
    { key: 'date', label: 'Date', sortable: true },
    { key: 'from', label: 'From', sortable: true },
    { key: 'to', label: 'To', sortable: true },
    { key: 'city', label: 'City', sortable: true },
}

dataBackend = [
    0 = { code: 1, description: 'Joel' },
    1 = { code: 2, description: 'Maria' },
    2 = { code: 3, description: 'Lucas' }
]

看法
项目:[
{日期:'01/01/2008',从:'1',到:'2',城市:'Paris'},
{日期:'06/03/2018',从:'3',到:'1',城市:'纽约'},
{日期:'05/06/2012',从:'3',到:'2',城市:'Tokyo'},
{日期:'2019年8月7日',从'2'到'3',城市:'Paris'}
]
字段:[
{key:'date',label:'date',sortable:true},
{key:'from',label:'from',sortable:true},
{key:'to',label:'to',sortable:true},
{key:'city',label:'city',sortable:true},
}
数据备份=[
0={code:1,description:'Joel'},
1={code:2,description:'Maria'},
2={代码:3,描述:'Lucas'}
]
当前:

预期结果:


您可以在两个字段上使用
格式化程序
功能来实现这一点

格式化程序将在每一行上运行,并接收单元格的值(在本例中为代码)。然后,您可以使用该值在后端数据中查找所需的对象,并返回描述

有关格式化程序的更多信息,请参见Bootstrap Vue文档中的
字段定义参考

newvue({
el:“#应用程序”,
数据(){
返回{
项目:[
{日期:'01/01/2008',从:'1',到:'2',城市:'Paris'},
{日期:'06/03/2018',从:'3',到:'1',城市:'纽约'},
{日期:'05/06/2012',从:'3',到:'2',城市:'Tokyo'},
{日期:'07/08/2019',从:'2',到:'3',城市:'Paris'},
{日期:2019年8月7日,从:'2'到:'4',城市:'哥本哈根'}
],
字段:[
{key:'date',label:'date',sortable:true},
{key:'from',label:'from',sortable:true,formatter:'getDescription'},
{key:'to',label:'to',sortable:true,formatter:'getDescription'},
{key:'city',label:'city',sortable:true}
],
数据备份:[
{代码:1,描述:'Joel'},
{代码:2,描述:'玛丽亚'},
{代码:3,描述:'Lucas'}
]
}
},
方法:{
getDescription(代码){
const data=this.dataBackend.find(data=>data.code==code)
返回数据?数据。说明:代码;
}
}
})


@Dcoder当前输入的值​​“From”和“To”列中的所有列都是根据“items”列表通过代码显示的,但是我想根据“dataBackend”对它们进行格式化列表,以便显示说明而不显示代码。如果我正在格式化的任何行没有dataBackend值,是否可以在这些行上返回原始值?