2
我正在研究搜索功能。我的實時數據庫中有超過2000種產品的列表。Firebase搜索查詢會給出不同的結果
我試着用3個查詢搜索Shampoo
。但是沒有一個查詢返回字符串「Shampoo」所需的產品名稱。
但是Query 1 & 2
返回下面的產品,如下圖所示,產品名稱節點中沒有「Shampoo」。
我想不通爲什麼會發生?
CODE
const databaseRef = firebase.database().ref('S01/Products');
// Search Query 1 - Shows Different Product (Refer above image)
var query = databaseRef.orderByChild("productName").startAt("Shampoo");
// Search Query 2 - Shows Different Product (Refer above image)
var query = databaseRef.orderByChild("productName").endAt("Shampoo");
// Search Query 3 - Shows Different Product (Refer above image)
var query = databaseRef.orderByChild("productName").startAt("Shampoo").endAt("~");
// Search Query 3 - Returns no Products
var query = databaseRef.orderByChild("productName").equalTo("Shampoo");
// Search Query 3 - Returns no Products
var query = databaseRef.orderByChild("productName").startAt("Shampoo").endAt("Shampoo" + "~");
query.once("value")
.then(function (snapshot) {
snapshot.forEach(function (childSnapshot) {
var t = $('#products_table').DataTable();
var key = childSnapshot.key;
var MID = childSnapshot.child("productMID").val();
var SID = childSnapshot.child("productSID").val();
var ProductID = childSnapshot.child("productID").val();
var name = childSnapshot.child("productName").val();
var unit = childSnapshot.child("productUnit").val();
var productMRP = childSnapshot.child("productMRP").val();
var price = childSnapshot.child("productSellingPrice").val();
var buying_price = childSnapshot.child("productBuyingPrice").val();
var productStatus = childSnapshot.child("productStatus").val();
var row = "";
t.row.add(['<td class="cell-60 responsive-hide"></td><td class="cell-300">', '<td>' + name + '</td>', '<td>' + unit + '</td>', '<td tabindex="1">' + productMRP + '</td>', '<td tabindex="2">' + price + '<\/td>', '<td tabindex="3">' + buying_price + '<\/td>', productStatus]).node().id = ProductID;
});
});