Leo*_*Leo 1 html javascript json formatter bootstrap-table
Javascript:
function LinkFormatter(value, row, index) {
return "<a href='"+row.url+"'>"+value+"</a>";
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<th data-field="snum" data-sortable="true" data-formatter="LinkFormatter" >LINK</th>
<th data-sortable="true">DATA</th>
Run Code Online (Sandbox Code Playgroud)
JSON:
{
data: [
[
"https://www.stackoverflow.com",
"Stackoverflow"
]
]
}
Run Code Online (Sandbox Code Playgroud)
对于这种组合,我仅在表的第一列中获得一个条目,该条目表示未定义,并且还链接到/ undefined。但是,我只想显示一列Stackoverflow的列,它是Stackoverflow的URL。
我想念什么?
小智 5
您将必须更改JSON。
应该是这样的:
[
{
"url": "https://www.stackoverflow.com",
"nice_name": "Stackoverflow"
},
{
"url": "https://www.facebook.com",
"nice_name": "Facebook"
}
];
Run Code Online (Sandbox Code Playgroud)
[
{
"url": "https://www.stackoverflow.com",
"nice_name": "Stackoverflow"
},
{
"url": "https://www.facebook.com",
"nice_name": "Facebook"
}
];
Run Code Online (Sandbox Code Playgroud)
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
});
});Run Code Online (Sandbox Code Playgroud)
通过数据字段初始化表时,需要相同JSON格式的引导表站点上的示例。例:
<table id="table"
data-toggle="table"
data-height="460"
data-url="../json/data1.json">
<thead>
Run Code Online (Sandbox Code Playgroud)