fix(plugin-export): filter non-existent fields

This commit is contained in:
chenos 2022-09-15 09:27:28 +08:00
parent 1a9cd78eb8
commit 12c3915a57
2 changed files with 3 additions and 3 deletions

View File

@ -10,10 +10,10 @@ export async function exportXlsx(ctx: Context, next: Next) {
if (typeof columns === 'string') {
columns = JSON.parse(columns);
}
const appends = columns2Appends(columns, ctx);
columns = columns?.filter((col) => col?.dataIndex?.length > 0);
const repository = ctx.db.getRepository<any>(resourceName, resourceOf) as Repository;
const collection = repository.collection;
columns = columns?.filter((col) => collection.hasField(col.dataIndex[0]) && col?.dataIndex?.length > 0);
const appends = columns2Appends(columns, ctx);
const data = await repository.find({
filter,
fields,

View File

@ -6,7 +6,7 @@ export function columns2Appends(columns, ctx) {
const appendColumns = [];
for (let i = 0, iLen = column.dataIndex.length; i < iLen; i++) {
let field = collection.getField(column.dataIndex[i]);
if (field.target) {
if (field?.target) {
appendColumns.push(column.dataIndex[i]);
collection = ctx.db.getCollection(field.target);
}