簡體   English   中英

提交web的表單firestore后如何重定向到新創建的文檔頁面

[英]How to redirect to newly created document page after submitting the form firestore for web

我想在成功創建文檔后重定向到新創建的文檔頁面。 下面是我的代碼

db.collection("problems").add({
                statement: statement,
                details: {
                    difficulty: difficulty,
                    type: type,
                    title: title
                },
                tags: tags,
                timestamp: {
                    created: firebase.firestore.Timestamp.now(),
                    modified: firebase.firestore.Timestamp.now()
                }
            })
            .then(function(docRef) {
                console.log("Document written with ID: ", docRef.id);
                var problemID;
                docRef.get()
                .then( (doc) => {
                    if(doc.exists) {
                        console.log(doc.data());
                        console.log(doc.id);
                        problemID = doc.id;
                        window.location.replace("/practice/problemID");
                    }
                })

            })

但這不起作用。 請告訴我我錯在哪里?

您需要 append 的 ID。

window.location.replace("/practice/"+problemID);

db.collection("problems").add({
                statement: statement,
                details: {
                    difficulty: difficulty,
                    type: type,
                    title: title
                },
                tags: tags,
                timestamp: {
                    created: firebase.firestore.Timestamp.now(),
                    modified: firebase.firestore.Timestamp.now()
                }
            })
            .then(function(docRef) {
                console.log("Document written with ID: ", docRef.id);
                var problemID;
                docRef.get()
                .then( (doc) => {
                    if(doc.exists) {
                        console.log(doc.data());
                        console.log(doc.id);
                        problemID = doc.id;
                        window.location.replace("/practice/"+problemID);
                    }
                })

            })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM