exports.del = function(req, res){
var id = req.body.id;
if(id){
Label.findById({_id : id}, function(err, label){
if(err) {console.log(err)}
let labelName = label.labelName;
if(!labelName){
for(let item of label.articleList){
(function(item){
console.log("fisrt:"+ item)
Article.findOne({articleTitle : item}, function(err, article){
let labelArr = article.articleLabel;
let index = labelArr.findIndex(function(label){
console.log(label, item)
return label == labelName
})
labelArr.splice(index, 1)
article.save(function(err, article){
if(err){ console.log(err)}
})
})
})(item)
}
}
})
Label.remove({_id : id}, function(err, label){
if(err){console.log(err)}
Label.fetch(function(err, label){
if(err){
console.log(err)
}
res.json(label)
})
})
}
}
when this interface is requested for the second time, the following error
TypeError: Cannot read property "labelName" of null
I really don"t have a deep understanding of js and node. I hope someone can help me explain and why? Thank you