Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript firebase查询方法startAt()采用区分大小写的参数_Javascript_Firebase_Firebase Realtime Database - Fatal编程技术网

Javascript firebase查询方法startAt()采用区分大小写的参数

Javascript firebase查询方法startAt()采用区分大小写的参数,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,此代码运行良好 我想要的唯一改进是-当我通过“Pi”时,它会获取所有以名称“Pi”开头的items对象,但当我输入“Pi”时,它不会返回任何结果 这意味着我希望这个方法startAt(itemName)不区分大小写。所以这应该适用于任何东西(小写或大写),比如“Pi”或“Pi”等等 Firebase中目前不支持小写搜索。处理此问题的最佳方法是将小写字符串存储在原始字符串旁边,然后查询小写字符串 var ref_restMenu = firebase.database().ref() .c

此代码运行良好

我想要的唯一改进是-当我通过“Pi”时,它会获取所有以名称“Pi”开头的items对象,但当我输入“Pi”时,它不会返回任何结果

这意味着我希望这个方法
startAt(itemName)
不区分大小写。所以这应该适用于任何东西(小写或大写),比如“Pi”或“Pi”等等


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");
    }
});
这确实需要复制数据,但到目前为止,还没有一个更容易预见的选择


参考:

问题在于,在查询时,您希望显示用户注册它的方式。然后显示非小写版本。您只使用小写字母进行查询,这并不意味着您需要显示它。
//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");
    }
});