gpt4 book ai didi

Android Firebase,Recyclerview 的服务器端过滤

转载 作者:行者123 更新时间:2023-11-30 00:55:49 24 4
gpt4 key购买 nike

以下是我的firebase数据结构

{
"ticketing" : {
"1476639649079-mahto" : {
"agentId" : 0,
"agent_status" : "1_Dispatched",
"approverId" : 0,
"contractorId" : 0,
"dateTime" : "16-10-2016 13:40 PM",
"priority" : "MEDIUM",
"requester" : {
"issue" : "issue 3",
"location" : "location 3",
"priority" : "Medium",
"shop" : "shop 3",
"site" : "site 3",
"userInfo" : {
"email" : "m@gmail.com",
"firstname" : "mahto",
"isLoggedin" : true,
"lastname" : "pancha",
"loggedin" : true,
"number" : "123123123",
"password" : "q",
"role" : "fieldagent",
"userid" : "2",
"username" : "q"
}
},
"requesterId" : 2,
"status" : "Incoming",
"ticketNumber" : "1476639649079-mahto"
},
"1476741838857-mahto" : {
"agentId" : 1,
"agent_status" : "1_Incoming",
"approverId" : 0,
"contractorId" : 0,
"dateTime" : "17-10-2016 18:03 PM",
"priority" : "HIGH",
"requester" : {
"issue" : "Description 3",
"location" : "Location 3",
"priority" : "HIGH",
"shop" : "shop 3",
"site" : "site 3",
"userInfo" : {
"email" : "m@gmail.com",
"firstname" : "mahto",
"isLoggedin" : true,
"lastname" : "pancha",
"loggedin" : true,
"number" : "123123123",
"password" : "q",
"role" : "fieldagent",
"userid" : "2",
"username" : "q"
}
},
"requesterId" : 2,
"status" : "Incoming",
"ticketNumber" : "1476741838857-mahto"
}
}
}

数据库引用

mDatabase = FirebaseDatabase.getInstance().getReference().child("ticketing");
mDatabase.orderByChild("agent_status").equalTo("1_Incoming");

并附加到 recyclerview 适配器

 mAdapter = new FirebaseRecyclerAdapter<Ticket, AgentTicketHolder>(Ticket.class, R.layout.agent_ticket_cardview, AgentTicketHolder.class, mDatabase) { .. }

我的预期结果是我只会得到一个节点,即 1476741838857-mahto,其 agent_status 值等于 1_Incoming

但是我在我的 recylerview 中得到了两个节点。

enter image description here

最佳答案

当您调用过滤方法时,Firebase SDK 会为生成的查询返回一个新对象。因此,您需要捕获对该对象的引用并将 that 传递给适配器:

mDatabase = FirebaseDatabase.getInstance().getReference().child("ticketing");

Query query = mDatabase.orderByChild("agent_status").equalTo("1_Incoming");

mAdapter = new FirebaseRecyclerAdapter<Ticket, AgentTicketHolder>
(Ticket.class, R.layout.agent_ticket_cardview, AgentTicketHolder.class, query) { .. }

关于Android Firebase,Recyclerview 的服务器端过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40184853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com