在使用Firestore、vuefire和vue-tables-2时,我遇到了获取文档ID的问题。
我的数据结构如下所示。
我的数据结构如下所示。
![enter image description here](https://istack.dev59.com/mQat6.webp)
<v-client-table :columns="columns" :data="devices" :options="options" :theme="theme" id="dataTable">
import { ClientTable, Event } from 'vue-tables-2'
import { firebase, db } from '../../firebase-configured'
export default {
name: 'Devices',
components: {
ClientTable,
Event
},
data: function() {
return {
devices: [],
columns: ['model', 'id', 'scanTime', 'isStolen'],
options: {
headings: {
model: 'Model',
id: 'Serial No',
scanTime: 'Scan Time',
isStolen: 'Stolen YN'
},
templates: {
id: function(h, row, index) {
return index + ':' + row.id // <<- row.id is undefined
},
isStolen: (h, row, index) => {
return row.isStolen ? 'Y': ''
}
},
pagination: {
chunk: 5,
edge: false,
nav: 'scroll'
}
},
useVuex: false,
theme: 'bootstrap4',
template: 'default'
}
},
firestore: {
devices: db.collection('devices')
},
};
我的期望是设备应该有 id
属性,就像 VueFire 文档中所述。
但是数组 this.devices
没有 id
字段,即使我检查控制台也没有。
deviceWithId
吗?代码如下:return this.devices.map(device => { let newDevice = {}; newDevice = Object.assign({}, device); newDevice.id = device.id; newDevices.push(newDevice)}
。我已经检查了device.id
,它有文档 ID。但是我卡在了如何传递这些参数上。 - sungyong