javascript - populating a bootstrap html table via jquery data - Stack Overflow

i just buil a data APIT trough Kimono -> .i would like to include it in a simple and nice bootstrap

i just buil a data APIT trough Kimono -> . i would like to include it in a simple and nice bootstrap table, like this: .html.

i just tried to insert the jquery code given by kimono

<script src=".10.1.min.js"></script>
<script>
function kimonoCallback(data) {
// do something with the data
// please make sure the scope of this function is global
}

$.ajax({
"url":";callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
 </script>

but i didn't manage to create the table. any advice?

i just buil a data APIT trough Kimono -> https://www.kimonolabs./api/2ewmh21u?apikey=lvafgzGqR6fOqrI0mXAbiPEmQGh7rR4m. i would like to include it in a simple and nice bootstrap table, like this: http://wenzhixin.cn/p/bootstrap-table/docs/examples.html.

i just tried to insert the jquery code given by kimono

<script src="http://code.jquery./jquery-1.10.1.min.js"></script>
<script>
function kimonoCallback(data) {
// do something with the data
// please make sure the scope of this function is global
}

$.ajax({
"url":"https://www.kimonolabs./api/2ewmh21u?apikey=lvafgzGqR6fOqrI0mXAbiPEmQGh7rR4m&callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
 </script>

but i didn't manage to create the table. any advice?

Share Improve this question asked Sep 11, 2014 at 15:14 andriatzandriatz 6222 gold badges9 silver badges22 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

you can active bootstrap table via javascript:

<table id="table">
  <thead>
    <tr>
      <th data-field="nome" data-formatter="linkFormatter">Nome</th>
      <th data-field="descrizione" data-formatter="linkFormatter">Descrizione</th>
    </tr>
  </thead>
</table>

<script>
function linkFormatter(value) {
  return '<a href="' + value.href + '">' + value.text + '</a>';
}

function kimonoCallback(data) {
  $('#table').bootstrapTable({
    data: data.results.collection1
  });
}

$.ajax({
  "url":"https://www.kimonolabs./api/2ewmh21u?apikey=lvafgzGqR6fOqrI0mXAbiPEmQGh7rR4m&callback=kimonoCallback",
  "crossDomain":true,
  "dataType":"jsonp"
});
 </script>

jsFiddle: http://jsfiddle/wenyi/8svjf80g/33/

I have no idea what you want to display from your JSONP feed, but generally you can handle the display like so:

<table class="table table-striped table-bordered">
  <thead>
    <tr>
      <th>Href</th>
      <th>Text</th>
    </tr>
  </thead>
  <tbody id="loadHere">
  </tbody>
</table>

<script src="http://code.jquery./jquery-1.10.1.min.js"></script>
<script>
function kimonoCallback(data) {
  // this will help you see data structure while you develop the table
  console.log(data);
  // then create your table
  var results = data.results.collection1,
     i;
  for (i = 0; i < results.length; i += 1) {
    $('#loadHere').append(
      '<tr>' +
        '<td>' + results[i].nome.href + '</td>' +
        '<td>' + results[i].nome.text + '</td>' +
      '<td>' +
    '</table>');
  }
}

$.ajax({
"url":"https://www.kimonolabs./api/2ewmh21u?apikey=lvafgzGqR6fOqrI0mXAbiPEmQGh7rR4m&callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
 </script>

Be sure to look at the console to see how the data is structured so you can determine which fields to populate the table with.

Well.. You need to actually make the table when kimonoCallback gets called.

See?

// do something with the data
// please make sure the scope of this function is global

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745469319a4629060.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信