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

firebase查询方法startAt()采用区分大小写的参数,第1张

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

Firebase当前不支持小写搜索。处理此问题的最佳方法是将小写字符串与原始字符串一起存储,然后查询小写字符串。

var ref_restMenu = firebase.database().ref()    .child('Restaurants')    .child('Company')    .child('menu');var item = "Apple Pie";// Or however you store dataref.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");    }});

这确实需要复制数据,但是到目前为止,还没有一个更容易预见的选项。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5440219.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存