Advertisement
Misipuk

home_old1

Jul 20th, 2021
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import wixData from 'wix-data';
  2. import wixFetch from 'wix-fetch';
  3.  
  4. $w.onReady(function () {
  5.     //load_hv_table()
  6.     load_opt_price()
  7. });
  8.  
  9.  
  10. async function load_hv_table() {
  11.    
  12.  
  13.     const res = await wixData.query('hv_data').find();
  14.     //var json = JSON.parse(res.items[0]["jsondata"])
  15.     console.log(res.items)
  16.     var json = JSON.parse(res.items[0]["jsondata"])
  17.     console.log(json)
  18.     //console.log(Object.keys(json[0]))
  19.     //await wixData.insert("temp", json[0])
  20.  
  21.     var cols = []
  22.     Object.keys(json[0]).forEach(key => {
  23.         if (key[0] != "_")
  24.             cols.push({
  25.                 "id": key.toString(),
  26.                 "label": key.toString(),
  27.                 "dataPath": key.toString(),
  28.                 // "width": 100,
  29.                 // "visible": true,
  30.                 // "type": "string"
  31.             })
  32.     })
  33.  
  34.    /* var keys = Object.keys(json[0])
  35.     //.sort()
  36.     for (let i=0; i<keys.length; i++){
  37.         if (keys[i][0] != "_"){
  38.             cols.push({
  39.                 "id": keys[i].toString(),
  40.                 "label": keys[i].toString(),
  41.                 "dataPath": keys[i].toString(),
  42.                 // "width": 100,
  43.                 // "visible": true,
  44.                 // "type": "string"
  45.             })
  46.         }
  47.     }*/
  48.     console.log(cols)
  49.     $w("#table1").columns = cols;
  50.     //console.log($w("#table1").columns);
  51.     $w('#table1').rows = json;
  52.     /*const myTableData = [
  53.         { "Name": "A", "28910": "0", "29520": "0", "30140": "0", "30750": "0", "31370": "0", "31990": "0" },
  54.         {"Name": "B", "28910": "0", "29520": "0","30140": "0","30750": "0","31370": "0","31990": "0"}
  55.     ];*/
  56.     //$w("#table2").rows = myTableData;
  57.     //const arr = JSON.parse(json);
  58.  
  59.     //const arr = JSON.parse(json);
  60.     //arr.forEach( obj => renameKey( obj, ) );
  61.     //const updatedJson = JSON.stringify( arr );
  62.  
  63.     //$w("#table2").rows = json
  64.     /*for(let i = 0; i < json.length; i++){
  65.         console.log(json[i])
  66.     }*/
  67. }
  68.  
  69. async function load_opt_price() {
  70.     const res = await wixData.query('opt_data').ascending("title").find();
  71.     var json = JSON.parse(res.items[0]["call1"])
  72.     console.log(json)
  73.     console.log(Object.keys(json[0]))
  74.     //await wixData.insert("temp", json[0])
  75.  
  76.     let cols = []
  77.     Object.keys(json[0]).forEach(key => {
  78.         if (key[0] != "_")
  79.             cols.push({
  80.                 "id": key.toString(),
  81.                 "label": key.toString(),
  82.                 "dataPath": key.toString().split('.')[0],
  83.                 // "width": 100,
  84.                 // "visible": true,
  85.                 // "type": "string"
  86.             })
  87.     })
  88.     $w("#table1").columns = cols;
  89.     //console.log($w("#table1").columns);
  90.    // $w('#table2').rows = json;
  91.     const myTableData = [
  92.         { "Name": "A", "28910": "0", "29520": "0", "30140": "0", "30750": "0", "31370": "0", "31990": "0" },
  93.         {"Name": "B", "28910": "0", "29520": "0","30140": "0","30750": "0","31370": "0","31990": "0"}
  94.     ];
  95.     $w("#table1").rows = myTableData;
  96.     //const arr = JSON.parse(json);
  97.  
  98.     //const arr = JSON.parse(json);
  99.     //arr.forEach( obj => renameKey( obj, ) );
  100.     //const updatedJson = JSON.stringify( arr );
  101.  
  102.     //$w("#table2").rows = json
  103.     /*for(let i = 0; i < json.length; i++){
  104.         console.log(json[i])
  105.     }*/
  106. }
  107.  
  108.    
  109.  
  110.  
  111. function renameKey ( obj, oldKey) {
  112.   obj[oldKey.split('.')[0]] = obj[oldKey];
  113.   delete obj[oldKey];
  114. }
  115.  
  116. async function loadData() {
  117.     const res = await wixData.query('Data').limit(200).find();
  118.     const data = res.items;
  119.     //$w('#table2').rows = data;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement