Javascript 从数组中删除项后出错
我尝试通过单击按钮从数据库中的数组中删除Javascript 从数组中删除项后出错,javascript,node.js,express,mongoose,Javascript,Node.js,Express,Mongoose,我尝试通过单击按钮从数据库中的数组中删除此项,但出现了错误,我看不到我的错误。我有错误:RangeError:超过了最大调用堆栈大小,更重要的是我有/api/editProduct/undefined 工厂: userFactory.deleteDescription = function(description) { return $http.delete('/api/editProduct/' + description) } 原料药 模型 点是删除所选项当您在expre
此
项,但出现了错误,我看不到我的错误。我有错误:RangeError:超过了最大调用堆栈大小,更重要的是我有/api/editProduct/undefined
工厂:
userFactory.deleteDescription = function(description) {
return $http.delete('/api/editProduct/' + description)
}
原料药
模型
点是删除所选项当您在expressjs路由中使用命名参数时,您可以通过
req.params['yourKey']
访问该值。在您的情况下,这将是req.params.description
因此,要删除某个产品中的描述条目,可以执行以下操作
Product.findOneAndUpdate(
{ _id: req.body_id },
{ $pull: { description: req.params.description }},
function(err, product){
...
}
);
和req.params.description相等。您确定正确调用了api吗?因为在你的问题中,你说你调用
/api/editProduct/undefined
。。这意味着req.params.description
的值是一个值为“undefined”的字符串,不等于undefined
。尝试使用/api/editProduct/someDescription
调用它,似乎一切都更好,但req.body\u id返回未定义
var productSchema = new Schema({
title: {
type: String,
require: true,
},
level: {
type: String,
require:true,
},
description: [{
type: String,
require: true,
}],
});
Product.findOneAndUpdate(
{ _id: req.body_id },
{ $pull: { description: req.params.description }},
function(err, product){
...
}
);