Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wixData from 'wix-data';
- import wixFetch from 'wix-fetch';
- $w.onReady(function () {
- //load_hv_table()
- load_opt_price()
- });
- async function load_hv_table() {
- const res = await wixData.query('hv_data').find();
- //var json = JSON.parse(res.items[0]["jsondata"])
- console.log(res.items)
- var json = JSON.parse(res.items[0]["jsondata"])
- console.log(json)
- //console.log(Object.keys(json[0]))
- //await wixData.insert("temp", json[0])
- var cols = []
- Object.keys(json[0]).forEach(key => {
- if (key[0] != "_")
- cols.push({
- "id": key.toString(),
- "label": key.toString(),
- "dataPath": key.toString(),
- // "width": 100,
- // "visible": true,
- // "type": "string"
- })
- })
- /* var keys = Object.keys(json[0])
- //.sort()
- for (let i=0; i<keys.length; i++){
- if (keys[i][0] != "_"){
- cols.push({
- "id": keys[i].toString(),
- "label": keys[i].toString(),
- "dataPath": keys[i].toString(),
- // "width": 100,
- // "visible": true,
- // "type": "string"
- })
- }
- }*/
- console.log(cols)
- $w("#table1").columns = cols;
- //console.log($w("#table1").columns);
- $w('#table1').rows = json;
- /*const myTableData = [
- { "Name": "A", "28910": "0", "29520": "0", "30140": "0", "30750": "0", "31370": "0", "31990": "0" },
- {"Name": "B", "28910": "0", "29520": "0","30140": "0","30750": "0","31370": "0","31990": "0"}
- ];*/
- //$w("#table2").rows = myTableData;
- //const arr = JSON.parse(json);
- //const arr = JSON.parse(json);
- //arr.forEach( obj => renameKey( obj, ) );
- //const updatedJson = JSON.stringify( arr );
- //$w("#table2").rows = json
- /*for(let i = 0; i < json.length; i++){
- console.log(json[i])
- }*/
- }
- async function load_opt_price() {
- const res = await wixData.query('opt_data').ascending("title").find();
- var json = JSON.parse(res.items[0]["call1"])
- console.log(json)
- console.log(Object.keys(json[0]))
- //await wixData.insert("temp", json[0])
- let cols = []
- Object.keys(json[0]).forEach(key => {
- if (key[0] != "_")
- cols.push({
- "id": key.toString(),
- "label": key.toString(),
- "dataPath": key.toString().split('.')[0],
- // "width": 100,
- // "visible": true,
- // "type": "string"
- })
- })
- $w("#table1").columns = cols;
- //console.log($w("#table1").columns);
- // $w('#table2').rows = json;
- const myTableData = [
- { "Name": "A", "28910": "0", "29520": "0", "30140": "0", "30750": "0", "31370": "0", "31990": "0" },
- {"Name": "B", "28910": "0", "29520": "0","30140": "0","30750": "0","31370": "0","31990": "0"}
- ];
- $w("#table1").rows = myTableData;
- //const arr = JSON.parse(json);
- //const arr = JSON.parse(json);
- //arr.forEach( obj => renameKey( obj, ) );
- //const updatedJson = JSON.stringify( arr );
- //$w("#table2").rows = json
- /*for(let i = 0; i < json.length; i++){
- console.log(json[i])
- }*/
- }
- function renameKey ( obj, oldKey) {
- obj[oldKey.split('.')[0]] = obj[oldKey];
- delete obj[oldKey];
- }
- async function loadData() {
- const res = await wixData.query('Data').limit(200).find();
- const data = res.items;
- //$w('#table2').rows = data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement