【发布时间】:2018-10-10 16:24:37
【问题描述】:
【问题讨论】:
标签: firebase firebase-realtime-database google-cloud-functions
【问题讨论】:
标签: firebase firebase-realtime-database google-cloud-functions
您可以先检索类别数据。假设您知道第一个键(LNBxRLsPR0OY8-_Cnm)并且您只有一个类别项目(如果多个类别将用另一个代码快照解释)
firebase.database().ref('product/' + key + '/categoria').once('value', snapshot=>{
if (snapshot.exists()) var categoriaKey = Object.keys(snapshot.val()[0])
firebase.database().ref('product/' + key + '/' + categoriaKey).set(newCategoriaObject)
})
编辑:
productList={}
firebase.database().ref('product').once('value', snap=>{
snap.forEach(p=>{
productList[p.key]=p.val().name;
})
})
上面的产品列表对象数组。场景:您需要向用户显示产品名称列表。用户选择产品后,您可以通过以下功能检索密钥。
function findKey(productList, selectedProductName) {
for (let key in productList)
if (productList[key] === selectedProductName) return key;
}
key = findKey(productList, selectedProductName);
因此,使用上述简单代码,您将获得用户选择的产品密钥。如果你没有其他场景:)
【讨论】: