Update app.js
This commit is contained in:
@@ -1375,18 +1375,11 @@ async function crmLoadRecords() {
|
|||||||
});
|
});
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
// Normalise: response may be [[{...},...]] or [{...},...] or {response:[...]}
|
// Shape: {data: [{...}, ...]}
|
||||||
let data;
|
let data = json?.data ?? json?.response ?? json;
|
||||||
if (Array.isArray(json)) {
|
// If the outer result wraps in an extra array like [{data:[...]}] handle that too
|
||||||
if (json.length > 0 && Array.isArray(json[0])) {
|
if (Array.isArray(data) && data.length > 0 && data[0]?.data) {
|
||||||
data = json[0];
|
data = data[0].data;
|
||||||
} else {
|
|
||||||
data = json;
|
|
||||||
}
|
|
||||||
} else if (json && json.response) {
|
|
||||||
data = json.response;
|
|
||||||
} else {
|
|
||||||
data = [];
|
|
||||||
}
|
}
|
||||||
crmRecords = Array.isArray(data) ? data : [];
|
crmRecords = Array.isArray(data) ? data : [];
|
||||||
crmRender();
|
crmRender();
|
||||||
|
|||||||
Reference in New Issue
Block a user