【发布时间】:2021-09-08 11:59:01
【问题描述】:
所以我有这段代码
// GET request for pokedex page
app.get("/pokedex", function (req, res) {
Pokemon.find(function (err, pokemon) {
if (err) {
console.log(err);
} else {
console.log(pokemon);
res.render("pokedex", { pokemon: pokemon });
}
});
});
它把数据发送到前端就好了。数据也会被正确记录到控制台。问题是当我在回调之前添加{ information: { primaryType: "Grass" } }, 时,它不会发送任何数据。唯一记录的是空数组,但我正在尝试过滤数据。
我正在使用 JS、Node、Express 和 EJS。我也对其他过滤数据的方法持开放态度。
型号
[
{
information: {
name: 'Bulbasaur',
dexNumber: 1,
primaryType: 'Grass',
secondaryType: 'Poison',
description: 'There is a plant seed on its back right from the day this Pokémon is born. The seed slowly grows larger.',
devolvedForm: null,
evolvedForm: 'Ivysaur'
},
stats: {
health: 45,
attack: 49,
specialAttack: 65,
defense: 49,
specialDefense: 65,
speed: 45
},
_id: 609cdab515102582ccf4e743,
__v: 0
},
【问题讨论】:
-
你能展示你的模型吗?
-
@CuongLeNgoc 我已将其添加到我的帖子中
标签: javascript api express mongoose