【心得6】10/19

 今天學習到「資料庫」的概念,使用了Google試算表的表格資料替代先前用array儲存的資料,除了可以方便更動資料,也能一次儲存大量的資料,也不會因為在程式碼區直接輸入大量資料,發生筆誤時還需要從編譯器debug才能正常運作,只是網頁會跑的比直接在程式碼輸入資料還要久才會顯示畫面,上次學到的分頁也能跟主頁從同一個資料庫呼叫資料來使用。

引算表時需開啟編輯頁複製目標頁面從d/到/pubhtml之間這段

<script src='https://cdnjs.cloudflare.com/ajax/libs/tabletop.js/1.5.1/tabletop.min.js'></script>
    <script type='text/javascript'> 
        var publicSpreadsheetUrl = 'https://docs.google.com/spreadsheets/d/編輯頁網址/pubhtml';

data就是試算表的資料,利用迴圈,可顯示「data[i].每欄名稱」,為那一欄的資料。

    function init() {
    Tabletop.init({
        key: publicSpreadsheetUrl,
        callback: showInfo,
        simpleSheet: true
        })
    }

    function showInfo(datatabletop) {
    // alert('Successfully processed!')
        console.log(data);
    var str = "";
        for (var i = 0i < data.lengthi++) {
        str += data[i].name + " <br />";
         }
        document.getElementById("demo").innerHTML = str;
        }
    window.addEventListener('DOMContentLoaded'init)




留言

  1. Google試算表的表格資料可以同時更動資料同時儲存大量的資料,就像有魚腦可以同時去夜店同時渣女友

    回覆刪除

張貼留言

這個網誌中的熱門文章

【心得12】12/14

【心得10】11/30

【心得11】12/06