I was integrate firebase with ionic3 angularjs, adding data successfully like
我将firebase与ionic3 angularjs集成,成功地添加了数据
var fireData =
{
userid : '1122233',
questionId : '18022',
answerId : '25633',
points : '2'
}
//Add
this.sample.list('paperCode').push(fireData);
Now I want to update like below mentioned image
现在我想像下面提到的图像更新
2 个解决方案
#1
0
If you don't know the key, first query the data with the field you know then iterate through the result and get the key. Then you can perform update.
如果您不知道密钥,首先使用您知道的字段查询数据,然后遍历结果并获取密钥。然后你可以执行更新。
Try
尝试
updateFunction(questionId){
this.sample.list('/paperCode', ref => ref.orderByChild('questionId').equalTo(questionId)).snapshotChanges()
.subscribe(actions => {
actions.forEach(action => {
// here you get the key
console.log(action.key);
this.sample.list('/paperCode').update(action.key, { points: 10 });
});
});
}
I hope your question id is unique, otherwise it will override all queried results.
我希望您的问题ID是唯一的,否则它将覆盖所有查询结果。
#2
0
You need to set a path to that object and update the field you would like. In this example...
您需要设置该对象的路径并更新您想要的字段。在这个例子中......
firebase.database().ref(1710172911409/L5F4BEuePS8qxUqDNoF/questionId).update("NEWQUESTIONID);
If you don't know the unique id of the pushed object, you can query for it. Learn more here
如果您不知道推送对象的唯一ID,则可以查询它。在这里了解更多
#1
0
If you don't know the key, first query the data with the field you know then iterate through the result and get the key. Then you can perform update.
如果您不知道密钥,首先使用您知道的字段查询数据,然后遍历结果并获取密钥。然后你可以执行更新。
Try
尝试
updateFunction(questionId){
this.sample.list('/paperCode', ref => ref.orderByChild('questionId').equalTo(questionId)).snapshotChanges()
.subscribe(actions => {
actions.forEach(action => {
// here you get the key
console.log(action.key);
this.sample.list('/paperCode').update(action.key, { points: 10 });
});
});
}
I hope your question id is unique, otherwise it will override all queried results.
我希望您的问题ID是唯一的,否则它将覆盖所有查询结果。
#2
0
You need to set a path to that object and update the field you would like. In this example...
您需要设置该对象的路径并更新您想要的字段。在这个例子中......
firebase.database().ref(1710172911409/L5F4BEuePS8qxUqDNoF/questionId).update("NEWQUESTIONID);
If you don't know the unique id of the pushed object, you can query for it. Learn more here
如果您不知道推送对象的唯一ID,则可以查询它。在这里了解更多