|
@@ -175,11 +175,22 @@ class CrudService extends NafService {
|
|
|
// 整理ref数据
|
|
|
rs = rs.map(i => {
|
|
|
for (const obj of refMods) {
|
|
|
- const { col, prop } = obj;
|
|
|
+ const { col, prop, type } = obj;
|
|
|
if (!prop) continue;
|
|
|
- if (isString(prop)) i = { ...omit(i, [ col ]), [`${col}_${prop}`]: get(i, `${col}.${prop}`), [col]: get(i, `${col}._id`) };
|
|
|
- else if (isArray(prop)) {
|
|
|
- for (const p of prop) i[`${col}_${p}`] = get(i, `${col}.${p}`);
|
|
|
+ if (isArray(prop)) {
|
|
|
+ for (const p of prop) {
|
|
|
+ if (type === 'String') i[`${col}_${p}`] = get(i, `${col}.${p}`);
|
|
|
+ if (type === 'Array') {
|
|
|
+ const list = [];
|
|
|
+ const oList = get(i, `${col}`);
|
|
|
+ for (const d of oList) {
|
|
|
+ const obj = { _id: d._id };
|
|
|
+ obj[p] = get(d, p);
|
|
|
+ list.push(obj);
|
|
|
+ }
|
|
|
+ i[`${col}_${p}`] = list;
|
|
|
+ }
|
|
|
+ }
|
|
|
i[col] = get(i, `${col}._id`);
|
|
|
}
|
|
|
}
|
|
@@ -194,7 +205,7 @@ class CrudService extends NafService {
|
|
|
const refMods = [];
|
|
|
for (const key in mod) {
|
|
|
if (!mod[key].ref) continue;
|
|
|
- refMods.push({ col: key, prop: mod[key].getProp });
|
|
|
+ refMods.push({ col: key, prop: mod[key].getProp, type: mod[key].type.name });
|
|
|
}
|
|
|
return refMods;
|
|
|
}
|