首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过jquery数据填充引导html表

通过jquery数据填充引导html表
EN

Stack Overflow用户
提问于 2014-09-11 23:14:34
回答 3查看 13.5K关注 0票数 1

我想把它包含在一个简单而漂亮的引导表中,就像这样:http://wenzhixin.net.cn/p/bootstrap-table/docs/examples.html

代码语言:javascript
复制
<script src="http://code.jquery.com/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.com/api/2ewmh21u?apikey=lvafgzGqR6fOqrI0mXAbiPEmQGh7rR4m&callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
 </script>

但是我没能成功地创建这个表。有什么建议吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-10-24 01:20:55

您可以通过javascript激活bootstrap表:

代码语言: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.com/api/2ewmh21u?apikey=lvafgzGqR6fOqrI0mXAbiPEmQGh7rR4m&callback=kimonoCallback",
  "crossDomain":true,
  "dataType":"jsonp"
});
 </script>

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

票数 2
EN

Stack Overflow用户

发布于 2014-09-11 23:53:35

我不知道您希望从JSONP提要中显示什么,但通常您可以这样处理显示:

代码语言:javascript
复制
<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.com/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.com/api/2ewmh21u?apikey=lvafgzGqR6fOqrI0mXAbiPEmQGh7rR4m&callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
 </script>

请务必查看控制台以了解数据是如何构造的,这样您就可以确定用哪些字段来填充表。

票数 0
EN

Stack Overflow用户

发布于 2014-09-11 23:16:08

好吧..。当kimonoCallback被调用时,您需要实际创建表。

看见?

代码语言:javascript
复制
// do something with the data
// please make sure the scope of this function is global
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25791178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档