-1
我嘗試從點擊按鈕的數據庫中的數組中刪除this
項目,但我得到錯誤,我看不到我的錯誤。我有錯誤:引發RangeError:最大調用堆棧大小超出,什麼是更重要的我有/api/editProduct/undefined
從數組中刪除項目後的錯誤
廠:
userFactory.deleteDescription = function(description) {
return $http.delete('/api/editProduct/' + description)
}
API
router.delete('/editProduct/:description', function(req, res){
Product.findOneAndUpdate({ _id: req.body_id }, { $pull: { description: this }}, function(err, product){
if(err) throw err;
if(!product){
res.json({ success: false, message: 'No user found' });
} else {
console.log('ok')
}
});
});
模型
var productSchema = new Schema({
title: {
type: String,
require: true,
},
level: {
type: String,
require:true,
},
description: [{
type: String,
require: true,
}],
});
刪除所選項目
這是行不通的,因爲產品等於空 –
而req.params .description is undefined –
你確定你正確地調用你的api嗎?因爲在你的問題中,你說你調用了'/ api/editProduct/undefined' ..這意味着'req.params.description'的值是一個值爲'undefined'的字符串,不等於'undefined'。 嘗試使用'/ api/editProduct/someDescription'調用它 – japrescott