[英]Expressjs Firebase React Redux Cannot set headers after they are sent to the client
[英]Expressjs - Cannot set headers after they are sent to the client
在嘗試其他人的解決方案時,這似乎無法為我解決此錯誤。 我想做的是for each I in the array
陣列中來自下方的for each I in the array
陣列
novel.ts
export let indexList = (req: Request, res: Response) => {
novel.getAllDocuments((data) => {
const novelObj = Convert.toNovelObj(data);
res.render(`novels/all`, {
title: `List of novels`,
array: {
name: novelObj.novelName,
author: novelObj.novelAuthor,
id: novelObj._id,
img: novelObj.novelCoverArt,
tags: novelObj.novelTags
}
});
});
};
novelObj
將我的MongoDB從json轉換為對象,如下所示
RiNovel.ts
public getAllDocuments(callback: (data) => void) {
var chapterInfoModel = mongoose.model('Novels', RiNovelcheme);
chapterInfoModel.collection
.find()
.stream()
.on('data', function(doc) {
const novelObj = Convert.novelObjToJson(doc);
return callback(novelObj);
})
.on('error', function(err) {
})
.on('end', function() {
});
}
all.pug
each i in array
p= i.name
錯誤是當我的收藏夾中有多個文檔時,我該如何解決
我發現這是我的解決方案
export let indexList = (req: Request, res: Response) => {
var chapterInfoModel = mongoose.model('Novels', RiNovelcheme);
chapterInfoModel.find().exec((err, novel) => {
if (err) {
res.send(err);
}
res.render('novels/all', {
title: 'All Novels',
name: novel
});
});
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.