答案 0 :(得分:1)
我建议将每个item0001
,item0002
删除,而不是使用firebase推送ID,您可以存储unix timestamp in millis
。这样,您可以轻松地对条目进行排序,并为每个项目获取最后一个子节点。
因此,通过此更改,您的数据库将显示为
root
user
uid
item0001
15089344450000 // this is a timestamp
itemdepositdate
itemwithdrawdate
15989922000000 // another timestamp
itemdepositdate
itemwithdrawdate
item0002
依旧......
现在,对于每个项目,您只需使用以下代码即可指向最后一个孩子。
FirebaseDatabase database = FirebaseDatabase.getInstance();
database.getReference()
.child("root")
.child("user")
.child("user_id_of_user")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
snapshot.getRef().orderByKey().limitToLast(1).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.getValue(); // this is the last itemdepositdate and itemwithdrawaldate for this item
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 1 :(得分:0)
<asp:Repeater ID="rptrBindBidders" onItemCommand="rptrBindBidders_ItemCommand" runat="server">
<HeaderTemplate>
<table class="table">
<thead>
<tr>
<th>Bidders</th>
<th>Date bidded</th>
<th>Price Offer</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("BidderName") %></td>
<td><%#Eval("DateBidded") %></td>
<td>₱<%# Eval("bidPrice") %></td>
<td><%# Eval("BidderStatus") %></td>
<td><asp:Button ID="btnSelectBuyer" runat="server" Text="Select Bidder" CommandName="Winner" CommandArgument='<%#Eval("bidID") %>'/></td>
<!--<asp:HiddenField ID="hfbidID" Value='' runat="server" />-->
<!--<asp:HiddenField ID="hfBidderName" Value='' runat="server" />-->
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>