第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 firestore 數(shù)據(jù)庫中獲取文檔 ID

如何從 firestore 數(shù)據(jù)庫中獲取文檔 ID

慕容3067478 2023-03-31 09:27:18
我正在嘗試通過調(diào)用檢索文檔 ID doc.getId(),但無法從此代碼調(diào)用它        db.collection("Pegawai").addSnapshotListener(new EventListener<QuerySnapshot>() {            @Override            public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {                if(e != null) {                    Log.d(TAG, e.toString());                }                if (queryDocumentSnapshots != null) {                    for (DocumentChange doc: queryDocumentSnapshots.getDocumentChanges()) {                        if (doc.getType() == DocumentChange.Type.ADDED) {                            Pegawai pegawai = doc.getDocument().toObject(Pegawai.class);                            pegawai.setId(doc.getId());                            pegawaiList.add(pegawai);                            pegawaiListAdapter.notifyDataSetChanged();                        }                    }                }            }        });我試過這段代碼,顯然,我可以用這段代碼調(diào)用,但這段代碼根本doc.getId()沒有填充我的代碼recyclerview        db.collection("Pegawai").addSnapshotListener(new EventListener<QuerySnapshot>() {            @Override            public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {                if(e != null) {                    Log.d(TAG, e.toString());                }                if (queryDocumentSnapshots != null) {                    for (DocumentSnapshot doc : queryDocumentSnapshots) {                        Pegawai pegawai = doc.toObject(Pegawai.class);                        pegawai.setId(doc.getId());                        pegawaiList.add(pegawai);                    }                }            }        });
查看完整描述

3 回答

?
炎炎設計

TA貢獻1808條經(jīng)驗 獲得超4個贊

如果您將 FirestoreRecyclerAdapter 與 Recyclerview 一起使用,請執(zhí)行此操作。

 DocumentSnapshot snapshot = options.getSnapshots().getSnapshot(position); 
            String dbKey = snapshot.getId();
            Log.d(TAG, "The database Key is : "+ dbKey);

然后你可以像這樣將它綁定在視圖持有者上

    holder.setDocumentId(dbKey);

然后你可以在任何地方檢索它,這取決于你的 getters 和 setters。我希望這會幫助那里的人。


查看完整回答
反對 回復 2023-03-31
?
侃侃無極

TA貢獻2051條經(jīng)驗 獲得超10個贊

DocumentChange對象具有返回QueryDocumentSnapshot對象的方法getDocument()。這是DocumentSnapshot的子類,這意味著它還有一個getId()方法。因此,您應該能夠使用來獲取正在處理的文檔的 ID。doc.getDocument().getId()



查看完整回答
反對 回復 2023-03-31
?
慕絲7291255

TA貢獻1859條經(jīng)驗 獲得超6個贊

以下是如何在 Javascript 中解決它,也許這將幫助您將其轉(zhuǎn)換為 Java。使用以下方法,我們可以動態(tài)檢索文檔 ID。請注意,我們使用snapshotChanges(). 這很重要,因為一旦我們訂閱了這個函數(shù),訂閱中就會包含文檔 ID。


saveMyValuesHere: any[] = []


getPegawai() {


    return this.db.collection('Pegawai').snapshotChanges();


  }


 getPegawai().subscribe(serverItems => {

      this.saveMyValuesHere = [];

      serverItems.forEach(a => {

        const data = a.payload.doc.data();

        const id = a.payload.doc.id;

        this.saveMyValuesHere.push({ id, ...data});

      });

    });


查看完整回答
反對 回復 2023-03-31
  • 3 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號