1 回答

TA貢獻1830條經(jīng)驗 獲得超9個贊
Firebase當前不支持小寫搜索。處理此問題的最佳方法是將小寫字符串與原始字符串一起存儲,然后查詢小寫字符串。
var ref_restMenu = firebase.database().ref()
.child('Restaurants')
.child('Company')
.child('menu');
var item = "Apple Pie";
// Or however you store data
ref.push({
itemName: item,
itemNameLower: item.toLowerCase(),
...
})
然后您可以這樣查詢:
//Check if item is already exist!
// query itemNameLoweruse and .toLowerCase()
ref_restMenu.orderByChild("itemNameLower").startAt(itemName.toLowerCase()).once("value", function(snapshot) {
var data = snapshot.val();
if(data !== null) {
//We will ger item name and restaurant id from this data.
callback(data);
} else {
//Item not found in globalMenu
console.log("%c Item not found in Global Menu", "color: red");
}
});
這確實需要復制數(shù)據(jù),但是到目前為止,還沒有一個更容易預見的選項。
添加回答
舉報