我有这个模型,我想让所有这个模型的孩子都用猫鼬,并显示一个UI。 我尝试使用递归函数,但是我的问题是我无法找回任何对象。
let postSchema = new mongoose.Schema({
name: String,
parent: String,
children: [String],
schoolId: String
});
我尝试递归类似波纹管的功能:
findunderposts = function(post){
var result = [];
Post.findOne({
_id:post
}).then(pfind=>{
if(pfind.children){
pfind.children.forEach(child=>{
result.push(findunderposts(child._id));
})
}else {
result.push(pfind);
return result;
}
})
};
当我这样做时,我没有从这部分得到任何东西:
resolve({ post:findunderposts(postId) })