排序json表jquery

问题描述 投票:0回答:2

我被卡住了......我需要从列表公式中获取sorting table ...我从JSON文件中获取了3个参数并创建公式,现在我需要对此公式列表进行排序。

Json文件:https://api.coinmarketcap.com/v1/ticker/

<body>
<script>
    $(document).ready(function() {

      $("#getMessage").on("click", function() {
        $.getJSON("https://api.coinmarketcap.com/v1/ticker/?limit=0", function(json) {

          var html = "";

        html += "<table id='myTable' class='display table' cellspacing = '0' width='100%'>"
        html += "<thead>"
        html += "<tr>"
        html += "<th>Name</th>"   
        html += "<th>Symbol</th>"        
        html += "<th>Market Cap</th>"       
        html += "<th>Circulating Supply</th>"       
        html += "<th>Volume (24h)</th>"       
        html += "<th>% 24h</th>" 
        html += "<th>Formula</th>"         
        html += "</tr>"    
        html += "</thead>"
        html += "<tfoot>"
        html += "<th>Name</th>"   
        html += "<th>Symbol</th>"        
        html += "<th>Market Cap</th>"       
        html += "<th>Circulating Supply</th>"       
        html += "<th>Volume (24h)</th>"       
        html += "<th>% 24h</th>" 
        html += "<th>Formula</th>"           
        html += "</tr>" 
        html += "</tfoot>"

          json.forEach(function(val) {

            var marketCap = val.market_cap_usd; 
            var _24h = val.percent_change_24h;
            var volume = val["24h_volume_usd"];
            var formula = [(((volume/((_24h/100)+1))/marketCap)*100)];

            html += "<tbody>"
            html += "<tr>"
            html += "<td>" + val.name + "</td>"
            html += "<td>" + val.symbol + "</td>"
            html += "<td>" + marketCap + "</td>"
            html += "<td>" + val.available_supply + "</td>"
            html += "<td>" + volume + "</td>"
            html += "<td>" + _24h + "</td>"
            html += "<td>" + formula + "</td>"
            html += "</tr>"
            html += "</tbody>"

          });

        html += "</table>"

          $(".message").html(html);

        });
      });

      $
    });
  </script>

<div class="row align-items-center justify-content-center" style="padding-top:10px; padding-bottom:10px">
  <button id="getMessage" class="btn btn-primary">Download</button>
</div>

    <div class = "col-xs-10 message text-center ">
      The data will go here
   </div>
</body>

我试图使用不同的插件,如jQuery排序列表,我试图使用Sort(),但它不起作用!也许我需要重写代码到JavaScript,而不是使用jQuery。现在对我来说非常痛苦!

jquery json ajax api dom
2个回答
0
投票
let myHtmlString = json.map(dataItem => ({...dataItem, formulaValue: formulaFunction(someValuesHere)}))
.sort((a, b) => a.formulaValue - b.formulaValue)
.map(dataItem => getMyHtml(dataItem))
.join('') ;

这就是你需要从json生成html字符串以使其工作的方式

ES5替代方案:

var myHtmlString = json.map(function(dataItem){
    return Object.assign(dataItem, {formulaValue: getFormulaValue(dataItem.value1, dataItem.value2)})
})
.sort(function(a,b) {
    return a.formulaValue - b.formulaValue;
})
.join('')

生成完整细节的html:

var json = [
 {
    "id": "bitcoin",
    "name": "Bitcoin",
    "symbol": "BTC",
    "rank": "1",
    "price_usd": "17123.0",
    "price_btc": "1.0",
    "24h_volume_usd": "19517400000.0",
    "market_cap_usd": "286887508976",
    "available_supply": "16754512.0",
    "total_supply": "16754512.0",
    "max_supply": "21000000.0",
    "percent_change_1h": "0.81",
    "percent_change_24h": "1.98",
    "percent_change_7d": "3.73",
    "last_updated": "1513837453"
  },
  {
    "id": "ethereum",
    "name": "Ethereum",
    "symbol": "ETH",
    "rank": "2",
    "price_usd": "869.983",
    "price_btc": "0.0510909",
    "24h_volume_usd": "3707510000.0",
    "market_cap_usd": "83928951501.0",
    "available_supply": "96471944.0",
    "total_supply": "96471944.0",
    "max_supply": null,
    "percent_change_1h": "-0.48",
    "percent_change_24h": "10.11",
    "percent_change_7d": "18.61",
    "last_updated": "1513837456"
  },
  {
    "id": "bitcoin-cash",
    "name": "Bitcoin Cash",
    "symbol": "BCH",
    "rank": "3",
    "price_usd": "3645.94",
    "price_btc": "0.214113",
    "24h_volume_usd": "7840660000.0",
    "market_cap_usd": "61498576564.0",
    "available_supply": "16867688.0",
    "total_supply": "16867688.0",
    "max_supply": "21000000.0",
    "percent_change_1h": "-1.11",
    "percent_change_24h": "4.78",
    "percent_change_7d": "101.97",
    "last_updated": "1513837473"
  },
  {
    "id": "ripple",
    "name": "Ripple",
    "symbol": "XRP",
    "rank": "4",
    "price_usd": "1.00682",
    "price_btc": "0.00005913",
    "24h_volume_usd": "2101900000.0",
    "market_cap_usd": "39003345815.0",
    "available_supply": "38739144847.0",
    "total_supply": "99993093880.0",
    "max_supply": "100000000000",
    "percent_change_1h": "2.95",
    "percent_change_24h": "33.03",
    "percent_change_7d": "87.87",
    "last_updated": "1513837441"
  },
  {
    "id": "litecoin",
    "name": "Litecoin",
    "symbol": "LTC",
    "rank": "5",
    "price_usd": "331.988",
    "price_btc": "0.0194964",
    "24h_volume_usd": "1795450000.0",
    "market_cap_usd": "18060390598.0",
    "available_supply": "54400733.0",
    "total_supply": "54400733.0",
    "max_supply": "84000000.0",
    "percent_change_1h": "1.55",
    "percent_change_24h": "0.39",
    "percent_change_7d": "9.3",
    "last_updated": "1513837442"
  },
  {
    "id": "iota",
    "name": "IOTA",
    "symbol": "MIOTA",
    "rank": "6",
    "price_usd": "5.24849",
    "price_btc": "0.00030822",
    "24h_volume_usd": "504427000.0",
    "market_cap_usd": "14588336895.0",
    "available_supply": "2779530283.0",
    "total_supply": "2779530283.0",
    "max_supply": "2779530283.0",
    "percent_change_1h": "0.69",
    "percent_change_24h": "3.59",
    "percent_change_7d": "26.81",
    "last_updated": "1513837467"
  },
  {
    "id": "cardano",
    "name": "Cardano",
    "symbol": "ADA",
    "rank": "7",
    "price_usd": "0.500688",
    "price_btc": "0.00002940",
    "24h_volume_usd": "179769000.0",
    "market_cap_usd": "12981373094.0",
    "available_supply": "25927070538.0",
    "total_supply": "31112483745.0",
    "max_supply": "45000000000.0",
    "percent_change_1h": "0.78",
    "percent_change_24h": "2.44",
    "percent_change_7d": "266.72",
    "last_updated": "1513837476"
  },
  {
    "id": "dash",
    "name": "Dash",
    "symbol": "DASH",
    "rank": "8",
    "price_usd": "1569.77",
    "price_btc": "0.092187",
    "24h_volume_usd": "740147000.0",
    "market_cap_usd": "12190512547.0",
    "available_supply": "7765795.0",
    "total_supply": "7765795.0",
    "max_supply": "18900000.0",
    "percent_change_1h": "0.23",
    "percent_change_24h": "18.21",
    "percent_change_7d": "68.23",
    "last_updated": "1513837443"
  },
  {
    "id": "nem",
    "name": "NEM",
    "symbol": "XEM",
    "rank": "9",
    "price_usd": "0.987425",
    "price_btc": "0.00005799",
    "24h_volume_usd": "118662000.0",
    "market_cap_usd": "8886824999.0",
    "available_supply": "8999999999.0",
    "total_supply": "8999999999.0",
    "max_supply": null,
    "percent_change_1h": "1.26",
    "percent_change_24h": "11.29",
    "percent_change_7d": "83.81",
    "last_updated": "1513837458"
  },
  {
    "id": "bitcoin-gold",
    "name": "Bitcoin Gold",
    "symbol": "BTG",
    "rank": "10",
    "price_usd": "442.455",
    "price_btc": "0.0259837",
    "24h_volume_usd": "581607000.0",
    "market_cap_usd": "7397116925.0",
    "available_supply": "16718349.0",
    "total_supply": "16818349.0",
    "max_supply": "21000000.0",
    "percent_change_1h": "0.22",
    "percent_change_24h": "-0.1",
    "percent_change_7d": "45.31",
    "last_updated": "1513837477"
  },
  {
    "id": "monero",
    "name": "Monero",
    "symbol": "XMR",
    "rank": "11",
    "price_usd": "459.682",
    "price_btc": "0.0269954",
    "24h_volume_usd": "594996000.0",
    "market_cap_usd": "7127121429.0",
    "available_supply": "15504461.0",
    "total_supply": "15504461.0",
    "max_supply": null,
    "percent_change_1h": "2.08",
    "percent_change_24h": "17.58",
    "percent_change_7d": "41.89",
    "last_updated": "1513837445"
  },
  {
    "id": "eos",
    "name": "EOS",
    "symbol": "EOS",
    "rank": "12",
    "price_usd": "11.7189",
    "price_btc": "0.00068821",
    "24h_volume_usd": "338053000.0",
    "market_cap_usd": "6480056740.0",
    "available_supply": "552957764.0",
    "total_supply": "1000000000.0",
    "max_supply": null,
    "percent_change_1h": "2.68",
    "percent_change_24h": "5.06",
    "percent_change_7d": "50.52",
    "last_updated": "1513837469"
  },
  {
    "id": "neo",
    "name": "NEO",
    "symbol": "NEO",
    "rank": "13",
    "price_usd": "76.2367",
    "price_btc": "0.0044771",
    "24h_volume_usd": "271758000.0",
    "market_cap_usd": "4955385500.0",
    "available_supply": "65000000.0",
    "total_supply": "100000000.0",
    "max_supply": null,
    "percent_change_1h": "0.01",
    "percent_change_24h": "14.28",
    "percent_change_7d": "53.75",
    "last_updated": "1513837460"
  },
  {
    "id": "qtum",
    "name": "Qtum",
    "symbol": "QTUM",
    "rank": "14",
    "price_usd": "66.0023",
    "price_btc": "0.00387607",
    "24h_volume_usd": "999105000.0",
    "market_cap_usd": "4867570622.0",
    "available_supply": "73748500.0",
    "total_supply": "100248500.0",
    "max_supply": null,
    "percent_change_1h": "0.23",
    "percent_change_24h": "6.21",
    "percent_change_7d": "261.94",
    "last_updated": "1513837467"
  },
  {
    "id": "stellar",
    "name": "Stellar",
    "symbol": "XLM",
    "rank": "15",
    "price_usd": "0.271485",
    "price_btc": "0.00001594",
    "24h_volume_usd": "253052000.0",
    "market_cap_usd": "4848374284.0",
    "available_supply": "17858718840.0",
    "total_supply": "103531054117",
    "max_supply": null,
    "percent_change_1h": "1.44",
    "percent_change_24h": "13.43",
    "percent_change_7d": "77.66",
    "last_updated": "1513837446"
  },
  {
    "id": "ethereum-classic",
    "name": "Ethereum Classic",
    "symbol": "ETC",
    "rank": "16",
    "price_usd": "46.0336",
    "price_btc": "0.00270339",
    "24h_volume_usd": "859968000.0",
    "market_cap_usd": "4535471948.0",
    "available_supply": "98525250.0",
    "total_supply": "98525250.0",
    "max_supply": null,
    "percent_change_1h": "2.09",
    "percent_change_24h": "10.58",
    "percent_change_7d": "45.25",
    "last_updated": "1513837464"
  },
  {
    "id": "tron",
    "name": "TRON",
    "symbol": "TRX",
    "rank": "17",
    "price_usd": "0.0634172",
    "price_btc": "0.00000372",
    "24h_volume_usd": "439705000.0",
    "market_cap_usd": "4169566272.0",
    "available_supply": "65748192475.0",
    "total_supply": "100000000000",
    "max_supply": null,
    "percent_change_1h": "-2.31",
    "percent_change_24h": "67.23",
    "percent_change_7d": "272.93",
    "last_updated": "1513837473"
  },
  {
    "id": "lisk",
    "name": "Lisk",
    "symbol": "LSK",
    "rank": "18",
    "price_usd": "21.2805",
    "price_btc": "0.00124972",
    "24h_volume_usd": "122284000.0",
    "market_cap_usd": "2471832732.0",
    "available_supply": "116154824.0",
    "total_supply": "116154824.0",
    "max_supply": null,
    "percent_change_1h": "-1.61",
    "percent_change_24h": "24.99",
    "percent_change_7d": "114.06",
    "last_updated": "1513837455"
  },
  {
    "id": "verge",
    "name": "Verge",
    "symbol": "XVG",
    "rank": "19",
    "price_usd": "0.154956",
    "price_btc": "0.00000910",
    "24h_volume_usd": "1051470000.0",
    "market_cap_usd": "2233737395.0",
    "available_supply": "14415301083.0",
    "total_supply": "14415301083.0",
    "max_supply": "16555000000.0",
    "percent_change_1h": "-1.16",
    "percent_change_24h": "109.91",
    "percent_change_7d": "939.46",
    "last_updated": "1513837449"
  },
  {
    "id": "zcash",
    "name": "Zcash",
    "symbol": "ZEC",
    "rank": "20",
    "price_usd": "685.741",
    "price_btc": "0.040271",
    "24h_volume_usd": "284248000.0",
    "market_cap_usd": "1975555533.0",
    "available_supply": "2880906.0",
    "total_supply": "2880906.0",
    "max_supply": null,
    "percent_change_1h": "1.21",
    "percent_change_24h": "10.91",
    "percent_change_7d": "46.78",
    "last_updated": "1513837459"
  },
  {
    "id": "omisego",
    "name": "OmiseGO",
    "symbol": "OMG",
    "rank": "21",
    "price_usd": "18.3068",
    "price_btc": "0.00107509",
    "24h_volume_usd": "144194000.0",
    "market_cap_usd": "1868072587.0",
    "available_supply": "102042552.0",
    "total_supply": "140245398.0",
    "max_supply": null,
    "percent_change_1h": "0.28",
    "percent_change_24h": "9.67",
    "percent_change_7d": "63.58",
    "last_updated": "1513837470"
  },
  {
    "id": "bitconnect",
    "name": "BitConnect",
    "symbol": "BCC",
    "rank": "22",
    "price_usd": "374.318",
    "price_btc": "0.0219823",
    "24h_volume_usd": "18946100.0",
    "market_cap_usd": "1854849742.0",
    "available_supply": "4955278.0",
    "total_supply": "9307440.0",
    "max_supply": "28000000.0",
    "percent_change_1h": "0.38",
    "percent_change_24h": "2.78",
    "percent_change_7d": "1.14",
    "last_updated": "1513837460"
  },
  {
    "id": "populous",
    "name": "Populous",
    "symbol": "PPT",
    "rank": "23",
    "price_usd": "42.1248",
    "price_btc": "0.00247383",
    "24h_volume_usd": "3392140.0",
    "market_cap_usd": "1737742612.0",
    "available_supply": "41252246.0",
    "total_supply": "53252246.0",
    "max_supply": "53252246.0",
    "percent_change_1h": "0.88",
    "percent_change_24h": "2.15",
    "percent_change_7d": "1.85",
    "last_updated": "1513837470"
  },
  {
    "id": "bitshares",
    "name": "BitShares",
    "symbol": "BTS",
    "rank": "24",
    "price_usd": "0.618512",
    "price_btc": "0.00003632",
    "24h_volume_usd": "149223000.0",
    "market_cap_usd": "1611613423.0",
    "available_supply": "2605630000.0",
    "total_supply": "2605630000.0",
    "max_supply": "3600570502.0",
    "percent_change_1h": "1.25",
    "percent_change_24h": "40.59",
    "percent_change_7d": "147.69",
    "last_updated": "1513837448"
  },
  {
    "id": "waves",
    "name": "Waves",
    "symbol": "WAVES",
    "rank": "25",
    "price_usd": "15.7902",
    "price_btc": "0.0009273",
    "24h_volume_usd": "82278200.0",
    "market_cap_usd": "1579020000.0",
    "available_supply": "100000000.0",
    "total_supply": "100000000.0",
    "max_supply": null,
    "percent_change_1h": "1.17",
    "percent_change_24h": "6.05",
    "percent_change_7d": "14.87",
    "last_updated": "1513837455"
  },
  {
    "id": "hshare",
    "name": "Hshare",
    "symbol": "HSR",
    "rank": "26",
    "price_usd": "37.0755",
    "price_btc": "0.00217731",
    "24h_volume_usd": "157513000.0",
    "market_cap_usd": "1571888609.0",
    "available_supply": "42396963.0",
    "total_supply": "42396963.0",
    "max_supply": "84000000.0",
    "percent_change_1h": "0.96",
    "percent_change_24h": "10.41",
    "percent_change_7d": "110.83",
    "last_updated": "1513837473"
  },
  {
    "id": "nxt",
    "name": "Nxt",
    "symbol": "NXT",
    "rank": "27",
    "price_usd": "1.37779",
    "price_btc": "0.00008091",
    "24h_volume_usd": "311813000.0",
    "market_cap_usd": "1376412129.0",
    "available_supply": "998999942.0",
    "total_supply": "998999942.0",
    "max_supply": "1000000000.0",
    "percent_change_1h": "4.47",
    "percent_change_24h": "59.79",
    "percent_change_7d": "96.17",
    "last_updated": "1513837441"
  },
  {
    "id": "ardor",
    "name": "Ardor",
    "symbol": "ARDR",
    "rank": "28",
    "price_usd": "1.33134",
    "price_btc": "0.00007818",
    "24h_volume_usd": "26946300.0",
    "market_cap_usd": "1330007988.0",
    "available_supply": "998999495.0",
    "total_supply": "998999495.0",
    "max_supply": "998999495.0",
    "percent_change_1h": "0.32",
    "percent_change_24h": "32.27",
    "percent_change_7d": "37.53",
    "last_updated": "1513837458"
  },
  {
    "id": "stratis",
    "name": "Stratis",
    "symbol": "STRAT",
    "rank": "29",
    "price_usd": "12.658",
    "price_btc": "0.00074336",
    "24h_volume_usd": "67726700.0",
    "market_cap_usd": "1248951711.0",
    "available_supply": "98668961.0",
    "total_supply": "98668961.0",
    "max_supply": null,
    "percent_change_1h": "3.53",
    "percent_change_24h": "17.05",
    "percent_change_7d": "30.77",
    "last_updated": "1513837457"
  }
];

function getFormulaValue(dataItem) {
  return (((dataItem['24h_volume_usd'] / ((dataItem.percent_change_24h / 100) + 1)) / dataItem.market_cap_usd) * 100);
}

var tableBodyHtml = json.map(function(dataItem) {
  return Object.assign(dataItem, {formulaValue: getFormulaValue(dataItem)});
})
.sort(function(a,b) {
  return b.formulaValue - a.formulaValue;
})
.map(function(dataItem) {
  return (
    "<tr>" +
    "<td>" + dataItem.name + "</td>" +
    "<td>" + dataItem.symbol + "</td>" +
    "<td>" + dataItem.market_cap_usd + "</td>" +
    "<td>" + dataItem.available_supply + "</td>" +
    "<td>" + dataItem['24h_volume_usd'] + "</td>" +
    "<td>" + dataItem.percent_change_24h + "</td>" +
    "<td>" + dataItem.formulaValue + "</td>" +
    "</tr>"
  )
})
.join('');

var html = '';

html += "<table id='myTable' class='display table' cellspacing = '0' width='100%'>"
html += "<thead>"
html += "<tr>"
html += "<th>Name</th>"
html += "<th>Symbol</th>"
html += "<th>Market Cap</th>"
html += "<th>Circulating Supply</th>"
html += "<th>Volume (24h)</th>"
html += "<th>% 24h</th>"
html += "<th>Formula</th>"
html += "</tr>"
html += "</thead>"
html += "<tfoot>"
html += "<th>Name</th>"
html += "<th>Symbol</th>"
html += "<th>Market Cap</th>"
html += "<th>Circulating Supply</th>"
html += "<th>Volume (24h)</th>"
html += "<th>% 24h</th>"
html += "<th>Formula</th>"
html += "</tr>"
html += "</tfoot>"
html += "<tbody>"

html += tableBodyHtml;

html += "</tbody>"
html += "</table>"

0
投票

 alert("j");
        $(document).ready(function() {
      
      var val =[
    {
        "id": "bitcoin", 
        "name": "Bitcoin", 
        "symbol": "BTC", 
        "rank": "1", 
        "price_usd": "17123.0", 
        "price_btc": "1.0", 
        "24h_volume_usd": "19517400000.0", 
        "market_cap_usd": "286887508976", 
        "available_supply": "16754512.0", 
        "total_supply": "16754512.0", 
        "max_supply": "21000000.0", 
        "percent_change_1h": "0.81", 
        "percent_change_24h": "1.98", 
        "percent_change_7d": "3.73", 
        "last_updated": "1513837453"
    }, 
    {
        "id": "ethereum", 
        "name": "Ethereum", 
        "symbol": "ETH", 
        "rank": "2", 
        "price_usd": "869.983", 
        "price_btc": "0.0510909", 
        "24h_volume_usd": "3707510000.0", 
        "market_cap_usd": "83928951501.0", 
        "available_supply": "96471944.0", 
        "total_supply": "96471944.0", 
        "max_supply": null, 
        "percent_change_1h": "-0.48", 
        "percent_change_24h": "10.11", 
        "percent_change_7d": "18.61", 
        "last_updated": "1513837456"
    }, 
    {
        "id": "bitcoin-cash", 
        "name": "Bitcoin Cash", 
        "symbol": "BCH", 
        "rank": "3", 
        "price_usd": "3645.94", 
        "price_btc": "0.214113", 
        "24h_volume_usd": "7840660000.0", 
        "market_cap_usd": "61498576564.0", 
        "available_supply": "16867688.0", 
        "total_supply": "16867688.0", 
        "max_supply": "21000000.0", 
        "percent_change_1h": "-1.11", 
        "percent_change_24h": "4.78", 
        "percent_change_7d": "101.97", 
        "last_updated": "1513837473"
    }, 
    {
        "id": "ripple", 
        "name": "Ripple", 
        "symbol": "XRP", 
        "rank": "4", 
        "price_usd": "1.00682", 
        "price_btc": "0.00005913", 
        "24h_volume_usd": "2101900000.0", 
        "market_cap_usd": "39003345815.0", 
        "available_supply": "38739144847.0", 
        "total_supply": "99993093880.0", 
        "max_supply": "100000000000", 
        "percent_change_1h": "2.95", 
        "percent_change_24h": "33.03", 
        "percent_change_7d": "87.87", 
        "last_updated": "1513837441"
    }, 
    {
        "id": "litecoin", 
        "name": "Litecoin", 
        "symbol": "LTC", 
        "rank": "5", 
        "price_usd": "331.988", 
        "price_btc": "0.0194964", 
        "24h_volume_usd": "1795450000.0", 
        "market_cap_usd": "18060390598.0", 
        "available_supply": "54400733.0", 
        "total_supply": "54400733.0", 
        "max_supply": "84000000.0", 
        "percent_change_1h": "1.55", 
        "percent_change_24h": "0.39", 
        "percent_change_7d": "9.3", 
        "last_updated": "1513837442"
    }, 
    {
        "id": "iota", 
        "name": "IOTA", 
        "symbol": "MIOTA", 
        "rank": "6", 
        "price_usd": "5.24849", 
        "price_btc": "0.00030822", 
        "24h_volume_usd": "504427000.0", 
        "market_cap_usd": "14588336895.0", 
        "available_supply": "2779530283.0", 
        "total_supply": "2779530283.0", 
        "max_supply": "2779530283.0", 
        "percent_change_1h": "0.69", 
        "percent_change_24h": "3.59", 
        "percent_change_7d": "26.81", 
        "last_updated": "1513837467"
    }, 
    {
        "id": "cardano", 
        "name": "Cardano", 
        "symbol": "ADA", 
        "rank": "7", 
        "price_usd": "0.500688", 
        "price_btc": "0.00002940", 
        "24h_volume_usd": "179769000.0", 
        "market_cap_usd": "12981373094.0", 
        "available_supply": "25927070538.0", 
        "total_supply": "31112483745.0", 
        "max_supply": "45000000000.0", 
        "percent_change_1h": "0.78", 
        "percent_change_24h": "2.44", 
        "percent_change_7d": "266.72", 
        "last_updated": "1513837476"
    }, 
    {
        "id": "dash", 
        "name": "Dash", 
        "symbol": "DASH", 
        "rank": "8", 
        "price_usd": "1569.77", 
        "price_btc": "0.092187", 
        "24h_volume_usd": "740147000.0", 
        "market_cap_usd": "12190512547.0", 
        "available_supply": "7765795.0", 
        "total_supply": "7765795.0", 
        "max_supply": "18900000.0", 
        "percent_change_1h": "0.23", 
        "percent_change_24h": "18.21", 
        "percent_change_7d": "68.23", 
        "last_updated": "1513837443"
    }, 
    {
        "id": "nem", 
        "name": "NEM", 
        "symbol": "XEM", 
        "rank": "9", 
        "price_usd": "0.987425", 
        "price_btc": "0.00005799", 
        "24h_volume_usd": "118662000.0", 
        "market_cap_usd": "8886824999.0", 
        "available_supply": "8999999999.0", 
        "total_supply": "8999999999.0", 
        "max_supply": null, 
        "percent_change_1h": "1.26", 
        "percent_change_24h": "11.29", 
        "percent_change_7d": "83.81", 
        "last_updated": "1513837458"
    }, 
    {
        "id": "bitcoin-gold", 
        "name": "Bitcoin Gold", 
        "symbol": "BTG", 
        "rank": "10", 
        "price_usd": "442.455", 
        "price_btc": "0.0259837", 
        "24h_volume_usd": "581607000.0", 
        "market_cap_usd": "7397116925.0", 
        "available_supply": "16718349.0", 
        "total_supply": "16818349.0", 
        "max_supply": "21000000.0", 
        "percent_change_1h": "0.22", 
        "percent_change_24h": "-0.1", 
        "percent_change_7d": "45.31", 
        "last_updated": "1513837477"
    }, 
    {
        "id": "monero", 
        "name": "Monero", 
        "symbol": "XMR", 
        "rank": "11", 
        "price_usd": "459.682", 
        "price_btc": "0.0269954", 
        "24h_volume_usd": "594996000.0", 
        "market_cap_usd": "7127121429.0", 
        "available_supply": "15504461.0", 
        "total_supply": "15504461.0", 
        "max_supply": null, 
        "percent_change_1h": "2.08", 
        "percent_change_24h": "17.58", 
        "percent_change_7d": "41.89", 
        "last_updated": "1513837445"
    }, 
    {
        "id": "eos", 
        "name": "EOS", 
        "symbol": "EOS", 
        "rank": "12", 
        "price_usd": "11.7189", 
        "price_btc": "0.00068821", 
        "24h_volume_usd": "338053000.0", 
        "market_cap_usd": "6480056740.0", 
        "available_supply": "552957764.0", 
        "total_supply": "1000000000.0", 
        "max_supply": null, 
        "percent_change_1h": "2.68", 
        "percent_change_24h": "5.06", 
        "percent_change_7d": "50.52", 
        "last_updated": "1513837469"
    }, 
    {
        "id": "neo", 
        "name": "NEO", 
        "symbol": "NEO", 
        "rank": "13", 
        "price_usd": "76.2367", 
        "price_btc": "0.0044771", 
        "24h_volume_usd": "271758000.0", 
        "market_cap_usd": "4955385500.0", 
        "available_supply": "65000000.0", 
        "total_supply": "100000000.0", 
        "max_supply": null, 
        "percent_change_1h": "0.01", 
        "percent_change_24h": "14.28", 
        "percent_change_7d": "53.75", 
        "last_updated": "1513837460"
    }, 
    {
        "id": "qtum", 
        "name": "Qtum", 
        "symbol": "QTUM", 
        "rank": "14", 
        "price_usd": "66.0023", 
        "price_btc": "0.00387607", 
        "24h_volume_usd": "999105000.0", 
        "market_cap_usd": "4867570622.0", 
        "available_supply": "73748500.0", 
        "total_supply": "100248500.0", 
        "max_supply": null, 
        "percent_change_1h": "0.23", 
        "percent_change_24h": "6.21", 
        "percent_change_7d": "261.94", 
        "last_updated": "1513837467"
    }, 
    {
        "id": "stellar", 
        "name": "Stellar", 
        "symbol": "XLM", 
        "rank": "15", 
        "price_usd": "0.271485", 
        "price_btc": "0.00001594", 
        "24h_volume_usd": "253052000.0", 
        "market_cap_usd": "4848374284.0", 
        "available_supply": "17858718840.0", 
        "total_supply": "103531054117", 
        "max_supply": null, 
        "percent_change_1h": "1.44", 
        "percent_change_24h": "13.43", 
        "percent_change_7d": "77.66", 
        "last_updated": "1513837446"
    }, 
    {
        "id": "ethereum-classic", 
        "name": "Ethereum Classic", 
        "symbol": "ETC", 
        "rank": "16", 
        "price_usd": "46.0336", 
        "price_btc": "0.00270339", 
        "24h_volume_usd": "859968000.0", 
        "market_cap_usd": "4535471948.0", 
        "available_supply": "98525250.0", 
        "total_supply": "98525250.0", 
        "max_supply": null, 
        "percent_change_1h": "2.09", 
        "percent_change_24h": "10.58", 
        "percent_change_7d": "45.25", 
        "last_updated": "1513837464"
    }, 
    {
        "id": "tron", 
        "name": "TRON", 
        "symbol": "TRX", 
        "rank": "17", 
        "price_usd": "0.0634172", 
        "price_btc": "0.00000372", 
        "24h_volume_usd": "439705000.0", 
        "market_cap_usd": "4169566272.0", 
        "available_supply": "65748192475.0", 
        "total_supply": "100000000000", 
        "max_supply": null, 
        "percent_change_1h": "-2.31", 
        "percent_change_24h": "67.23", 
        "percent_change_7d": "272.93", 
        "last_updated": "1513837473"
    }, 
    {
        "id": "lisk", 
        "name": "Lisk", 
        "symbol": "LSK", 
        "rank": "18", 
        "price_usd": "21.2805", 
        "price_btc": "0.00124972", 
        "24h_volume_usd": "122284000.0", 
        "market_cap_usd": "2471832732.0", 
        "available_supply": "116154824.0", 
        "total_supply": "116154824.0", 
        "max_supply": null, 
        "percent_change_1h": "-1.61", 
        "percent_change_24h": "24.99", 
        "percent_change_7d": "114.06", 
        "last_updated": "1513837455"
    }, 
    {
        "id": "verge", 
        "name": "Verge", 
        "symbol": "XVG", 
        "rank": "19", 
        "price_usd": "0.154956", 
        "price_btc": "0.00000910", 
        "24h_volume_usd": "1051470000.0", 
        "market_cap_usd": "2233737395.0", 
        "available_supply": "14415301083.0", 
        "total_supply": "14415301083.0", 
        "max_supply": "16555000000.0", 
        "percent_change_1h": "-1.16", 
        "percent_change_24h": "109.91", 
        "percent_change_7d": "939.46", 
        "last_updated": "1513837449"
    }, 
    {
        "id": "zcash", 
        "name": "Zcash", 
        "symbol": "ZEC", 
        "rank": "20", 
        "price_usd": "685.741", 
        "price_btc": "0.040271", 
        "24h_volume_usd": "284248000.0", 
        "market_cap_usd": "1975555533.0", 
        "available_supply": "2880906.0", 
        "total_supply": "2880906.0", 
        "max_supply": null, 
        "percent_change_1h": "1.21", 
        "percent_change_24h": "10.91", 
        "percent_change_7d": "46.78", 
        "last_updated": "1513837459"
    }, 
    {
        "id": "omisego", 
        "name": "OmiseGO", 
        "symbol": "OMG", 
        "rank": "21", 
        "price_usd": "18.3068", 
        "price_btc": "0.00107509", 
        "24h_volume_usd": "144194000.0", 
        "market_cap_usd": "1868072587.0", 
        "available_supply": "102042552.0", 
        "total_supply": "140245398.0", 
        "max_supply": null, 
        "percent_change_1h": "0.28", 
        "percent_change_24h": "9.67", 
        "percent_change_7d": "63.58", 
        "last_updated": "1513837470"
    }, 
    {
        "id": "bitconnect", 
        "name": "BitConnect", 
        "symbol": "BCC", 
        "rank": "22", 
        "price_usd": "374.318", 
        "price_btc": "0.0219823", 
        "24h_volume_usd": "18946100.0", 
        "market_cap_usd": "1854849742.0", 
        "available_supply": "4955278.0", 
        "total_supply": "9307440.0", 
        "max_supply": "28000000.0", 
        "percent_change_1h": "0.38", 
        "percent_change_24h": "2.78", 
        "percent_change_7d": "1.14", 
        "last_updated": "1513837460"
    }, 
    {
        "id": "populous", 
        "name": "Populous", 
        "symbol": "PPT", 
        "rank": "23", 
        "price_usd": "42.1248", 
        "price_btc": "0.00247383", 
        "24h_volume_usd": "3392140.0", 
        "market_cap_usd": "1737742612.0", 
        "available_supply": "41252246.0", 
        "total_supply": "53252246.0", 
        "max_supply": "53252246.0", 
        "percent_change_1h": "0.88", 
        "percent_change_24h": "2.15", 
        "percent_change_7d": "1.85", 
        "last_updated": "1513837470"
    }, 
    {
        "id": "bitshares", 
        "name": "BitShares", 
        "symbol": "BTS", 
        "rank": "24", 
        "price_usd": "0.618512", 
        "price_btc": "0.00003632", 
        "24h_volume_usd": "149223000.0", 
        "market_cap_usd": "1611613423.0", 
        "available_supply": "2605630000.0", 
        "total_supply": "2605630000.0", 
        "max_supply": "3600570502.0", 
        "percent_change_1h": "1.25", 
        "percent_change_24h": "40.59", 
        "percent_change_7d": "147.69", 
        "last_updated": "1513837448"
    }, 
    {
        "id": "waves", 
        "name": "Waves", 
        "symbol": "WAVES", 
        "rank": "25", 
        "price_usd": "15.7902", 
        "price_btc": "0.0009273", 
        "24h_volume_usd": "82278200.0", 
        "market_cap_usd": "1579020000.0", 
        "available_supply": "100000000.0", 
        "total_supply": "100000000.0", 
        "max_supply": null, 
        "percent_change_1h": "1.17", 
        "percent_change_24h": "6.05", 
        "percent_change_7d": "14.87", 
        "last_updated": "1513837455"
    }, 
    {
        "id": "hshare", 
        "name": "Hshare", 
        "symbol": "HSR", 
        "rank": "26", 
        "price_usd": "37.0755", 
        "price_btc": "0.00217731", 
        "24h_volume_usd": "157513000.0", 
        "market_cap_usd": "1571888609.0", 
        "available_supply": "42396963.0", 
        "total_supply": "42396963.0", 
        "max_supply": "84000000.0", 
        "percent_change_1h": "0.96", 
        "percent_change_24h": "10.41", 
        "percent_change_7d": "110.83", 
        "last_updated": "1513837473"
    }, 
    {
        "id": "nxt", 
        "name": "Nxt", 
        "symbol": "NXT", 
        "rank": "27", 
        "price_usd": "1.37779", 
        "price_btc": "0.00008091", 
        "24h_volume_usd": "311813000.0", 
        "market_cap_usd": "1376412129.0", 
        "available_supply": "998999942.0", 
        "total_supply": "998999942.0", 
        "max_supply": "1000000000.0", 
        "percent_change_1h": "4.47", 
        "percent_change_24h": "59.79", 
        "percent_change_7d": "96.17", 
        "last_updated": "1513837441"
    }, 
    {
        "id": "ardor", 
        "name": "Ardor", 
        "symbol": "ARDR", 
        "rank": "28", 
        "price_usd": "1.33134", 
        "price_btc": "0.00007818", 
        "24h_volume_usd": "26946300.0", 
        "market_cap_usd": "1330007988.0", 
        "available_supply": "998999495.0", 
        "total_supply": "998999495.0", 
        "max_supply": "998999495.0", 
        "percent_change_1h": "0.32", 
        "percent_change_24h": "32.27", 
        "percent_change_7d": "37.53", 
        "last_updated": "1513837458"
    }, 
    {
        "id": "stratis", 
        "name": "Stratis", 
        "symbol": "STRAT", 
        "rank": "29", 
        "price_usd": "12.658", 
        "price_btc": "0.00074336", 
        "24h_volume_usd": "67726700.0", 
        "market_cap_usd": "1248951711.0", 
        "available_supply": "98668961.0", 
        "total_supply": "98668961.0", 
        "max_supply": null, 
        "percent_change_1h": "3.53", 
        "percent_change_24h": "17.05", 
        "percent_change_7d": "30.77", 
        "last_updated": "1513837457"
    }
];
      
              var html = "";
    
            html += "<table id='myTable' class='display table' cellspacing = '0' width='100%'>"
            html += "<thead>"
            html += "<tr>"
            html += "<th>Name</th>"   
            html += "<th>Symbol</th>"        
            html += "<th>Market Cap</th>"       
            html += "<th>Circulating Supply</th>"       
            html += "<th>Volume (24h)</th>"       
            html += "<th>% 24h</th>" 
            html += "<th>Formula</th>"         
            html += "</tr>"    
            html += "</thead>"
            html += "<tfoot>"
            html += "<th>Name</th>"   
            html += "<th>Symbol</th>"        
            html += "<th>Market Cap</th>"       
            html += "<th>Circulating Supply</th>"       
            html += "<th>Volume (24h)</th>"       
            html += "<th>% 24h</th>" 
            html += "<th>Formula</th>"           
            html += "</tr>" 
            html += "</tfoot>"
    
              //json.forEach(function(val) {
                $.each(val , function (i, item) {
                var marketCap = item.market_cap_usd; 
                var _24h = item.percent_change_24h;
                var volume = item["24h_volume_usd"];
                var formula = [(((volume/((_24h/100)+1))/marketCap)*100)];
    
                html += "<tbody>"
                html += "<tr>"
                html += "<td>" + item.name + "</td>"
                html += "<td>" + item.symbol + "</td>"
                html += "<td>" + marketCap + "</td>"
                html += "<td>" + item.available_supply + "</td>"
                html += "<td>" + volume + "</td>"
                html += "<td>" + _24h + "</td>"
                html += "<td>" + formula + "</td>"
                html += "</tr>"
                html += "</tbody>"
      
              });
    
            html += "</table>"
      
              $(".message").html(html);
      
          
        });
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
  
    
    <div class="row align-items-center justify-content-center" style="padding-top:10px; padding-bottom:10px">
      <button id="getMessage" class="btn btn-primary">Download</button>
    </div>
    
        <div class = "col-xs-10 message text-center ">
          The data will go here
       </div>
    </body>

这是这段代码

© www.soinside.com 2019 - 2024. All rights reserved.