1. Problem description:
(1) after looking at the question of bootstrap table how to display the data after getting the data from the background , I found that the format of the data I returned from the background did not follow the format of {" total ": dataNum," rows ": [{}]}. But now I seem to have been converted to the correct format, but there is still no way to render the table.
(2) and have seen another problem bootstrap table returns data in the same format as the official data cannot be displayed at the front end , and then I see that I have set up server paging, but it still does not solve my problem.
2. Related code:
Front-end js
function initTable(){
$("-sharpmyProgress").bootstrapTable({
url: "api/studentRole/myProgress",
method: "get",
// dataType: "json",
// contentType: "application/json; charset=utf-8",
// contentType: "application/x-www-form-urlencoded",
cache: false, //
showColumns: true, //
showRefresh: true, //
showToggle:true, //
rowStyle: rowStyles, //
pagination: true, //
pageNumber: 1, //
pageSize: 10, //
pageList: [10,20,50], //
sidePagination: "server",
onLoadSuccess: function(result)
{
console.log("result: "+result);
},
onLoadError: function(err)
{
console.log("error: "+err);
},
columns: [
{
field: "index",
title: "",
align: "center",
formatter: runningFormatter
},
{
field: "id",
title: "",
align: "center"
},
{
field: "name",
title: "",
align: "center"
},
{
field: "dormitory",
title: "",
align: "center"
},
{
field: "room",
title: "",
align: "center"
},
{
field: "item",
title: "",
align: "center"
},
{
field: "operation",
title: "",
align: "center"
// ,formatter: operateFormatter,
// events: window.operateEvents
}]
});//end-bootstrapTable
}//end-initTable
and attach the relevant back-end code:
router.get("/studentRole/myProgress", function(req, res, next)
{
//
var userInfo = JSON.parse(req.cookies.get("userInfo"));
//!!!new
var result = {"total": "", "rows": []}; //
//
Apply.findOne({sid: userInfo.username}, function(err, docs)
{
if(!err)
{
if(docs != "" && docs != null)
{
result.rows.push({id: docs.sid, name: docs.name, dormitory: docs.dormitory, room: docs.room, item: ""});
result.total = result.rows.length;
}//end-if
}//end-if(!err)
});//end-Apply.findOne
//
Fix.find({id: userInfo.username}, function(err, doc)
{
if(!err)
{
if(doc != "" && doc != null)
{
for(let i = 0; i < doc.length; i PP)
{
result.rows.push({id: doc[i].id, name: doc[i].name, dormitory: doc[i].building, room: doc[i].room, item: "" });
}
//total
result.total = result.rows.length;
res.json(result);
return;
}
}
});//end-Fix.find
});//end-
3. Screenshot of error report: