...
HTML |
---|
<script> function build_dataset_table(table) { table.addClass("confluenceTable").addClass("tablesorter"); var tr = $("<tr>").addClass("sortableHeader").appendTo(table); var th = $('<th class="confluenceTh sortableHeader" data-column="0">').appendTo(tr); th.text("Loading table..."); $.ajax({url:"https://api.ecmwf.int/v1/datasets?key=key1", dataType : 'jsonp', success : function(data) { var th = $('<th class="confluenceTh sortableHeader" data-column="2">').appendTo(tr); th.text("Description"); var th = $('<th class="confluenceTh sortableHeader" data-column="1">').appendTo(tr); th.text("Licence"); $.each(data.datasets,function (i, d) { var tr = $("<tr>").appendTo(table); var td = $('<td class="confluenceTd">').appendTo(tr); td.text(d.name); var td = $('<td class="confluenceTd">').appendTo(tr); td.text(d.description); var td = $('<td class="confluenceTd">').appendTo(tr); if(d.licence) { var a = $("a").attr("href",d.licence.url).text(d.licence.name); a.appendTo(trtd); } else { td.text("N/A"); } }); th.text("Dataset"); }, error: function() { th.text("Failed to load table"); }}); } </script> <div class="table-wrap"> <table id="datasets_table"></table> </div> <script> build_dataset_table($("#datasets_table")); </script> |
...