我有一个分页和ext json的表,但我在执行表时遇到错误,任何人都可以帮助我,下面是json和代码已经在下面给出,相同的代码需要修改,提前谢谢。我有一个分页和ext json的表,但我在执行表时遇到错误,任何人都可以帮助我,下面是json和下面给出的代码,相同的代码需要修改,提前谢谢
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>bootstrap-table pagination</title>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.0/bootstrap-table.min.css'>
<style>
.pagination .active a {
width: 40px;
height: 34px;
-webkit-transform: skew(-21deg);
position: relative;
overflow: hidden;
background: red;
}
.pagination .active span{
-webkit-transform: skew(0deg) !important;
width: 40px !important;
height: 34px !important;
}
.pagination>li>a{
width: 40px;
height: 34px;
-webkit-transform: skew(-21deg);
background: #fff;
}
.pagination > li.page-pre >a,.pagination > li.page-next >a {
width: 85px !important;
}
.fixed-table-pagination div.pagination{
margin-right:20px;
}
.pagination-detail{
display:none;
}
.major{
background-color:green;
}
.critical{
background-color:orange;
}
</style>
</head>
<body>
<table id="table" data-show-header="true" data-pagination="true"
data-id-field="name"
data-page-list="[5, 10, 25, 50, 100, ALL]"
data-page-size="5">
<thead><tr><th>Name</th><th>stargazers_count</th><th>forks_count</th><th>description</th></tr></thead>
<tbody>
</tbody>
</table>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.js'></script>
<script>
$.ajax({
type:"GET",
contentType: "application/json; charset=UTF-8",
dataType: 'json',
cache:false,
url:"http://localhost/members.json"
success: function (data) {
console.log(data);
var test = members;
$.each(test, function(i, ele){
$('table#table TBODY').append('<tr><td>'+elem.name+'</td><td>'+elem.stargazerscount +'</td><td class="'+ elem.forkscount +'">'+elem.forkscount +'</td><td>'+elem.description +'</td></tr>');
});
}
} )
/* var series = [];
var dmJSON = "http://localhost/test/members.json";
$.getJSON( dmJSON, function(data) {
$.each(data.series, function(i, item) {
$('<tr class="text-center">').html(
"<td>"+item.data+"</td>").appendTo('#msg');
});
});
$('#msg').append(data);
$.each(data.myMonths, function (index, item) {
})
*/
/* var a = {};
$.getJSON('members.json', function (data) {
a = data;
$.each(a, function(idx, elem){
$('table#table TBODY').append('<tr><td>'+elem.name+'</td><td>'+elem.stargazerscount +'</td><td class="'+ elem.forkscount +'">'+elem.forkscount +'</td><td>'+elem.description +'</td></tr>');
});
});
*/
$(function () {
$('#table').bootstrapTable({
// data: data
});
});
</script>
</body>
</html>
members.json
{
"members": [{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "major",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "major",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
}
]
}
答案 0 :(得分:1)
如果将$ .each函数替换为:
$.each(a, function(idx, elem){
$('table#table TBODY').append('<tr><td>'+elem.name+'</td><td>'+elem.stargazerscount +'</td><td class="'+ elem.forkscount +'">'+elem.forkscount +'</td><td>'+elem.description +'</td></tr>');
});
然后将以下代码添加到您的样式组件中,然后您就会得到您的期望:
.major{
background-color:green;
}
.critical{
background-color:orange;
}
答案 1 :(得分:0)
我用其他json格式解决了这个问题,但是当我们检查元素
时,我需要在特定的tr中添加相同类的td<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>bootstrap-table pagination</title>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.0/bootstrap-table.min.css'>
<style>
.pagination .active a {
width: 40px;
height: 34px;
-webkit-transform: skew(-21deg);
position: relative;
overflow: hidden;
background: red;
}
.pagination .active span{
-webkit-transform: skew(0deg) !important;
width: 40px !important;
height: 34px !important;
}
.pagination>li>a{
width: 40px;
height: 34px;
-webkit-transform: skew(-21deg);
background: #fff;
}
.pagination > li.page-pre >a,.pagination > li.page-next >a {
width: 85px !important;
}
.fixed-table-pagination div.pagination{
margin-right:20px;
}
.pagination-detail{
display:none;
}
.major{
background-color:green;
}
.critical{
background-color:orange;
}
</style>
</head>
<body>
<table id="table" data-show-header="true" data-pagination="true"
data-id-field="name"
data-page-list="[5, 10, 25, 50, 100, ALL]"
data-page-size="5">
<thead><tr><th>Name</th><th>stargazers_count</th><th>forks_count</th><th>description</th></tr></thead>
<tbody>
</tbody>
</table>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js'></script>
<script src='js/bootstrap-table.js'></script>
<script>
$.ajax({
url: "http://localhost/bspaginationtable/ext-json/members.json",
type: "POST",
dataType:"json",
success: function (response)
{
// var trHTML = '';
$.each(response, function (key,value) {
$('table#table TBODY').append('<tr><td>'+value.name+'</td><td>'+value.stargazerscount +'</td><td class="'+ value.forkscount +'"><span>'+value.forkscount +'</span></td><td>'+value.description +'</td></tr>');
});
// $('#table').append(trHTML);
}
});
$(function () {
$('#table').bootstrapTable({
// data: data
});
});
</script>
</body>
</html>
json格式
[{
"name": "bootstrap-tables",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "major",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "major",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
},
{
"name": "bootstrap-table",
"stargazerscount": 526,
"forkscount": "critical",
"description": "ssssssssss"
}
]