(input)
| 70 | } |
| 71 | |
| 72 | export function buildTableViewData(input) { |
| 73 | const candidates = getArrayObjectCandidates(input); |
| 74 | if (candidates.length) { |
| 75 | const best = candidates.sort((a, b) => b.rows.length - a.rows.length)[0]; |
| 76 | return { |
| 77 | title: best.path === '$' ? '根数组表格视图' : best.path + ' 表格视图', |
| 78 | sourcePath: best.path, |
| 79 | ...buildRowsFromObjects(best.rows) |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | if (isPlainObject(input)) { |
| 84 | return { |
| 85 | title: '对象键值表视图', |
| 86 | sourcePath: '$', |
| 87 | ...buildKeyValueRows(input) |
| 88 | }; |
| 89 | } |
| 90 | |
| 91 | throw new Error('当前 JSON 不适合表格展示。建议使用对象数组,或包含对象数组字段的 JSON。'); |
| 92 | } |
| 93 | |
| 94 | export function isRenderableTableViewData(tableViewData) { |
| 95 | if (!tableViewData || !Array.isArray(tableViewData.rows) || !tableViewData.rows.length) { |
no test coverage detected