请大神帮我看下datatable怎样动态向表中写入sTitle值
$(document).ready(function(){$.get("page/cpu/usage.json",function(data){if(data.msg!=...
$(document).ready(function(){
$.get("page/cpu/usage.json", function (data) {
if (data.msg != "success") {
return
}
$("#cpu").dataTable({
aaData: data.data,
aoColumns:[
{sTitle:data.title[0]},
{sTitle:data.title[1]},
{sTitle:data.title[2]},
{sTitle:data.title[3]},
],
bAutoWidth: false,
}).fadeIn();
}, "json");
})
希望能将aoColumns中动态无限写入data.title[i],i值不确定。 展开
$.get("page/cpu/usage.json", function (data) {
if (data.msg != "success") {
return
}
$("#cpu").dataTable({
aaData: data.data,
aoColumns:[
{sTitle:data.title[0]},
{sTitle:data.title[1]},
{sTitle:data.title[2]},
{sTitle:data.title[3]},
],
bAutoWidth: false,
}).fadeIn();
}, "json");
})
希望能将aoColumns中动态无限写入data.title[i],i值不确定。 展开
1个回答
展开全部
$(document).ready(function () {
$.get("page/cpu/usage.json", function (data) {
if (data.msg != "success") {
return;
}
var temp = new Array();
for (var i = 0; i < data.length; i++)
temp.push({ "sTitle": data.title[i] });
$("#cpu").dataTable({
aaData: data.data,
aoColumns: temp,
bAutoWidth: false
}).fadeIn();
}, "json");
})
$.get("page/cpu/usage.json", function (data) {
if (data.msg != "success") {
return;
}
var temp = new Array();
for (var i = 0; i < data.length; i++)
temp.push({ "sTitle": data.title[i] });
$("#cpu").dataTable({
aaData: data.data,
aoColumns: temp,
bAutoWidth: false
}).fadeIn();
}, "json");
})
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询