javascript - 如何检索包含特定字符串的特定对象
问题描述
我有一个包含一系列 JSON 对象(练习)的数据库,我想只过滤和检索那些具有特定字符串的对象。
我下面的方法检索所有这些,我提供了特定的字符串(pathExercice)作为参数,但我不确定如何使用它来仅选择包含它的对象。
这是我目前在我的数据库中拥有的数据示例。在这种情况下,如果我的方法中提供的 pathExercice 与我的对象中的字符串匹配,我想检索这个对象
有什么线索吗?谢谢你
-Le7BeKeG9Zes6mZ7gUm
date: 1557063173016
pathExercice: "DeveloppeCouche"
reps: 10
weight: 10
export const readUserData = async (pathExercice) => {
let userID = firebase.auth().currentUser.uid
let ref = firebase.database().ref('users/' + userID + '/exercices')
return ref.once("value").then(snapshot => {
console.log(snapshot.val());
return snapshot.val()
}).catch(err => {
console.log('error: ' + err);
});
}
解决方案
found the solution, thx to those who have taken the time to read my post.
export const readUserData = async (pathExercice) => {
let userID = firebase.auth().currentUser.uid
let ref = firebase.database().ref('users/' + userID + '/exercices')
return ref.orderByChild('pathExercice').equalTo(pathExercice).once("value")
.then(snapshot => {
console.log(snapshot.val());
return snapshot.val()
}).catch(err => {
console.log('error: ' + err);
});
}
推荐阅读
- haskell - 如何在 Haskell 中从计算机加载 GIF 图像?
- angular - 如何在Angular2应用程序的双簧管节点事件中匹配每个新行分隔的json对象?
- wpf - 在 WPF 中显示容器的动态宽度
- c# - 如何将 C++ 程序链接到 Visual Studio 之外的 C# DLL?
- react-native - 如何检查用户是否活跃在本机反应中?
- php - VS Code 在 php 类中自动生成接口方法?
- mqtt - MQTT PAHO - 用于确认消息传递成功的 MessageId
- .net - 没有为泛型类调用 ICorProfilerCallback::ClassUnloadStarted,即使该类已卸载
- apache - XSL 在 PDF 中呈现 PDF
- azure - 带有 Haproxy 的 Azure 负载均衡器导致 504 超时