Javascript 在引导表中传递JSON数据
引导表未按预期工作。不从数据url获取数据。我已经传递了保存JSON数据的url。请建议如何解决这个问题。已包含从表组织获取数据的index.jsJavascript 在引导表中传递JSON数据,javascript,json,node.js,mongoose,bootstrap-table,Javascript,Json,Node.js,Mongoose,Bootstrap Table,引导表未按预期工作。不从数据url获取数据。我已经传递了保存JSON数据的url。请建议如何解决这个问题。已包含从表组织获取数据的index.js app.get(“/organizations”,函数(req,res){ 查找({},函数(err,allOrganizations){ 如果(错误){ 控制台日志(err); }否则{ res.send(所有组织); } }); }); 名称 位置 接触 您可以使用它将数据引入前端。 然后将其显示为以下内容: //display the da
app.get(“/organizations”,函数(req,res){
查找({},函数(err,allOrganizations){
如果(错误){
控制台日志(err);
}否则{
res.send(所有组织);
}
});
});代码>
名称
位置
接触
您可以使用它将数据引入前端。
然后将其显示为以下内容:
//display the data
const displayData = (orgs) => {
//here you can get table by giving it id
//if its the only table, then you could
const table = document.getElementsByTagName('table')[0];
let res = '<tbody>'
orgs.map(org => {
res += '<tr>'
+ '<td>' + org.location + '</td>'
+ '<td>' + org.contact + '</td>'
+ '</tr>'
})
res += '</tbody>'
table.innerHTML += res;
}
//fetch the data from the endpoint
const fetchData = async () => {
const url = 'http://localhost:3000/organizations' //here enter your app URL and port correctly
const res = await fetch(url)
const orgs = await res.json()
displayData(orgs)
}
window.onload = fetchData()
//显示数据
常量显示数据=(组织)=>{
//在这里,您可以通过提供表id来获取表
//如果这是唯一的桌子,那么你可以
const table=document.getElementsByTagName('table')[0];
设res=''
org.map(org=>{
res+=''
+“+org.location+”
+“+org.contact+”
+ ''
})
res+=''
table.innerHTML+=res;
}
//从端点获取数据
const fetchData=async()=>{
常量url=http://localhost:3000/organizations“//在此处正确输入应用程序URL和端口
const res=等待获取(url)
const orgs=wait res.json()
显示数据(orgs)
}
window.onload=fetchData()
正如我所说,bootstrap表不会从url@JamesZWell获取数据。实际上,你并没有这么说,你在我的评论后将其编辑成了问题,但至少现在更好了