URL的Bootstrap表格式化程序 [英] Bootstrap Table Formatter for URL

查看:79
本文介绍了URL的Bootstrap表格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript:

Javascript:

function LinkFormatter(value, row, index) {
  return "<a href='"+row.url+"'>"+value+"</a>";
}

HTML:

<th data-field="snum" data-sortable="true" data-formatter="LinkFormatter" >LINK</th>
<th data-sortable="true">DATA</th>

JSON:

{
  data: [
    [
      "https://www.stackoverflow.com",
      "Stackoverflow"
    ]
  ]
}

对于这种组合,我只在表的第一列中获得一个条目,该条目表示未定义,并且还链接到/undefined.但是,我只想要一列显示Stackoverflow的列,它是Stackoverflow的URL.

For this combination I only get an entry in the first column in the table that sais undefined and also links to /undefined. I however just want one column that display Stackoverflow and is a URL to stackoverflow.

我想念什么?

推荐答案

您将不得不更改JSON.

You will have to change your JSON.

应该是这样的:

[ 
  {
    "url": "https://www.stackoverflow.com",
    "nice_name": "Stackoverflow"
  },
  {
    "url": "https://www.facebook.com",
    "nice_name": "Facebook"
  }
];

var data = [{
  "url": "https://www.stackoverflow.com",
  "nice_name": "Stackoverflow"
}, {
  "url": "https://www.facebook.com",
  "nice_name": "Facebook"
}];

function linkFormatter(value, row) {
  return "<a href='" + row.url + "'>" + row.nice_name + "</a>";
}

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

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">

<table data-toggle="#table" id="table">
  <thead>
    <tr>
      <th data-field="url" data-formatter="linkFormatter" data-sortable="true">Link</th>
    </tr>
  </thead>
</table>

引导表站点上的示例,其中使用相同的JSON通过数据字段初始化表时需要格式.示例:

Example on bootstrap-table site where same JSON format is required when initializing table through data fields. Example:

<table id="table"
       data-toggle="table"
       data-height="460"
       data-url="../json/data1.json">
  <thead>

Bootstrap文档& 示例

这篇关于URL的Bootstrap表格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆