markdown JS.JSON.Study at edX - 显示远程数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown JS.JSON.Study at edX - 显示远程数据相关的知识,希望对你有一定的参考价值。

"use strict";
// Retrieve data from remote server.
function fGetData() {
    fetch("https://gist.githubusercontent.com/heiswayi/7fde241975ed8a80535a/raw/ff1caaeaf62bd6740ab7cafcd61f1215de173379/datatables-data.json")
        .then(function(response) {
            return response.json();
        })
        .then(function(jsObj) {
            fDynTable(jsObj);
        })
        .catch(function(error) {
            console.log(error.message);
        });
}

// Build table with the data from remote server.
function fDynTable(tableData) {
    var table1 = document.createElement("table");
    var tcaption1 = table1.createCaption();
    var tbody1 = table1.createTBody();
    var tcaption1Text = document.createTextNode("Dynamic Table with Some Data From Some URL");
    //var howManyRows = tableData.data.lenght;
    tcaption1.appendChild(tcaption1Text);
    tableData.data.forEach(function(somePerson) {
        var tRow1 = tbody1.insertRow();
        somePerson.forEach(function(cellData) {
            var tCell = tRow1.insertCell();
            var tCellText = document.createTextNode(cellData);
            tCell.appendChild(tCellText);
        });
    });
    document.body.appendChild(table1);
    fTableStyle();
}

// Apply some style to the table.
function fTableStyle() {
    var table1 = document.querySelector("table");
    var rowsOdd = table1.querySelectorAll("tr:nth-child(odd)");
    var td1 = table1.querySelectorAll("td");
    td1.forEach(function(tdCur) {
        tdCur.style.padding = "10px";
    });
    rowsOdd.forEach(function(rowCur) {
        rowCur.style.backgroundColor = "lime";
    });
}
fGetData();
JS.JSON.Study at edX - Displaying remote data
---------------------------------------------


A [Pen](https://codepen.io/Onlyforbopi/pen/mzbmrB) by [Pan Doul](https://codepen.io/Onlyforbopi) on [CodePen](https://codepen.io).

[License](https://codepen.io/Onlyforbopi/pen/mzbmrB/license).

以上是关于markdown JS.JSON.Study at edX - 显示远程数据的主要内容,如果未能解决你的问题,请参考以下文章

markdown JQuery Detect Scroll at Bottom(经过测试)

markdown JS.JSON.PERSONALSTORAGE.Study at edX - 使用Web存储播放废话

markdown 在Laravel中使用验证实现Recaptcha:https://www.cloudways.com/blog/use-recaptcha-laravel-forms-validat

解决跨域Access to XMLHttpRequest at ‘http://localhost:8080/xxx’ from origin ‘http://localhost:63342

phpredis Redis阵列 Redis Arrays

请问啥是AT指令?