Here is my solution!
you can follow my steps if you get a obstruct!
https://github.com/gildata/RAIO/issues/61
steps
- objects to array,
{{},{}} => arr = [{},{}];
for in & key
- get object's title ,
title = key;
for in & key
- create a new object
obj = {title, arr};
Object.assign(obj, {new_key: "new value"});
- wrapped array ,
array.push(obj);
for of / for in
- just use the wrapped array
array.map() & Table
// fetch data by `ReportName` & `GetRowSchema`
outputClick = () => {
fetch(`https://cdn.xgqfrms.xyz/json/tables.json`)
.then((response) => response.json())
.then((json)=> {
console.log(`json = ${json}`);
console.log(`json.length = ${json.length}`);
console.log(`json.Info`, json.Info.schema.Properties);
// Properties
let datas = [];
if(json.Info.schema.Properties !== undefined){
// datas.BasicInformationRow.Properties
datas = json.Info.schema.Properties;
}else{
let tables = json.Info.schema;
// let i = 0;
for (let key in tables) {
let arr = [];
let new_obj = {};
let i = 0;
if(!tables.hasOwnProperty(key)) continue;
if (tables.hasOwnProperty(key)) {
let title = tables[key].desc,
objs = tables[key].Properties;
for (let key in objs) {
if (objs.hasOwnProperty(key)) {
// A0
objs[key].name = key;
objs[key].key = ("k000" + i++);
}
arr.push(objs[key]);
console.log(`arr ${key}`, arr);
}
console.log(`title ${key}`, title);
new_obj.title = tables[key].desc;
new_obj.datas = arr;
console.log(`new obj = `, new_obj);
}
datas.push(new_obj);
const css = `
color: #0f0;
font-size: 23px;
`;
const css2 = `
color: #f00;
font-size: 16px;
`;
console.log(`%c datas key = ${key} \n datas = `, css, datas);
console.log(`%c datas i = ${i} \n datas = `, css2, datas[i]);
// i++;
}
}
console.log(`datas[0] = `, datas[0]);
console.log(`datas[0].length = `, datas[0].length);
// Array.isArrray(datas[0]);
console.log(`Array.isArray(datas[0]) = `, Array.isArray(datas[0]));
console.log(`typeof datas[0] = `, typeof(datas[0]));
this.setState(
{
output_datas: datas
}
);
return datas;
});
};