【发布时间】:2020-12-07 10:49:04
【问题描述】:
我从 firebase 获取云存储的数据,它也成功了,但它没有排序。 当我获取静态数据时,它就完成了工作, 我不明白我的错误在哪里, 我尝试更多次来解决这个问题,但无法解决, 请有人帮助我..
提前谢谢你:)
<script>
$(document).ready(function() {
$('#myTable1').DataTable();
} );
var firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
const booksRef = firebase.firestore().collection("JSDATA");
booksRef.get().then(function (querySnapshot){
querySnapshot.forEach(function (doc) {
document.getElementById("myTable1").innerHTML += "<tbody> <tr> <td>" + doc.data().Email + "</td> <td>" + doc.data().Password + "</td> </tr> </tbody>"
console.log(doc.data().Email);
});
});
console.log("hii");
booksRef.get().then((snapshot) => {
const data = snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}));
console.log("All data in 'books' collection", data);
// const userdata = document.querySelector("#myTable1");
// [ { id: 'glMeZvPpTN1Ah31sKcnj', title: 'The Great Gatsby' } ]
});
</script>
<html>
<head>
<title>Frestore Data</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>FireStore Data</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-analytics.js"></script>
</head>
<body>
<div class="container">
<table class="table table-striped table-bordered" id="myTable1">
<thead>
<tr>
<!-- <th class="th-sm" scope="col">Sr.No</th> -->
<th class="th-sm" scope="col">Email</th>
<th class="th-sm" scope="col">Password</th>
</tr>
</thead>
<tbody>
<tr>
<!-- <td></td> -->
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
在这张图片中,数据是 Firestore 的,它没有排序..
使用静态数据,它运行完美..
【问题讨论】:
-
您要在哪个字段上排序?电子邮件?
-
不是任何单个字段我想对所有字段进行排序,例如datatables.net
标签: javascript html firebase google-cloud-firestore