firebase,如何更新一个关键的数据 [英] firebase, how to update data at a key
问题描述
在持久化时,I
push()
一个对象列表(在本例中为Trip)到一个节点。 稍后,我检索它,并在单击按钮时进行更新(在这种情况下,更新出价信息)。我似乎无法找到一个简单的方法来做到这一点,除非之前我已经推动了旅程,我不得不手动调用
getkey()
,然后更新auto-生成uid到对象Trip本身。任何想法很容易做到这一点? $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b .Rayout.item_message,
TripViewHolder.class,
mFirebaseDatabaseReference.child(CHILD_TRIPS)){
$ b @Override
protected void populateViewHolder(TripViewHolder viewHolder,模型,int位置){
viewHolder.btnTakeNow.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Bid bidAtReserved = new Bid(mDriverCarInfo,model,MY_PRICE);
mFirebaseDatabaseReference.child(CHILD_TRIPS)
//这里我要更新出价, b $ b //除非我有
// ma,否则我无法得到这次旅行的uid push()。setValue(bidAtReserved);这是一个很好的例子。
}
});
}
};
我不确定你在尝试什么(相关的JSON的一小部分 - 作为文本,而不是截图 - 将是有益的)。但我最好的猜测是你正在寻找 getRef()
。
<$ c $保存无效的populateViewHolder(TripViewHolder viewHolder,最后旅行模型,最终诠释位置){
viewHolder.btnTakeNow.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
)mFirebaseAdapter.getRef(position).child(price).setValue(MY_PRICE);
}
});
}
I have some difficulties in updating an object at a bucket (key).
At the time of persistence, I push()
a list of objects (in this case, Trip) to a node.
Later, I retrieved it, and make an update (in this case, updating the bid info) when a button is clicked. I can't seem to find an easy way to do that, unless when I had pushed the trip before, I had to manually call getkey()
and then update the auto-generated uid to the object Trip itself. Any idea to get it done easily? thanks
mFirebaseAdapter = new FirebaseRecyclerAdapter<Trip,
TripViewHolder>(
Trip.class,
R.layout.item_message,
TripViewHolder.class,
mFirebaseDatabaseReference.child(CHILD_TRIPS)) {
@Override
protected void populateViewHolder(TripViewHolder viewHolder, final Trip model, int position) {
viewHolder.btnTakeNow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bid bidAtReserved = new Bid(mDriverCarInfo, model, MY_PRICE);
mFirebaseDatabaseReference.child(CHILD_TRIPS)
//here, I want to update the bidding to this trip, but
//I can't get the uid of the trip, unless I had
//manually recorded at the time of pushing the trip
.child(model.getUid())
.child("bids").push().setValue(bidAtReserved);
}
});
}
};
I'm not really sure what you're trying to accomplish (a snippet of the relevant JSON - as text, not a screenshot - would be helpful). But my best guess is that you're looking for getRef()
.
protected void populateViewHolder(TripViewHolder viewHolder, final Trip model, final int position) {
viewHolder.btnTakeNow.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mFirebaseAdapter.getRef(position).child("price").setValue(MY_PRICE);
}
});
}
这篇关于firebase,如何更新一个关键的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!