【问题标题】:MEAN stack delete平均堆栈删除
【发布时间】:2015-10-28 01:09:19
【问题描述】:

尝试在我的帖子列表中添加一个删除按钮,这将从数据库中删除条目,但只有在单击该按钮时才会变为空。

我的 $scope

$scope.remove = function(post) {
  posts.remove(post);
}

此功能的链接:

o.remove = function(post) {
    $http({ url: '/posts/' + post._id, 
            method: 'DELETE'                
    }).then(function(res) {
        // Deleted
        console.log(data);
        // Update list
        $http.get("/posts")
            .success(function(data, status, headers, config) {
              console.log(data);                
        });
    }, function(error) {
        console.log(error);
    });

 };

路由器:

router.delete('/posts/:post', function(req, res, next) {
        Post.remove({
            _id : req.params.id
        }, function(err, post) {
            if (err)
                res.send(err);

            Post.find(function(err, post) {
                if (err)
                    res.send(err)
                res.json(post);
            });
        });
    });

按钮

    <span ng-click="remove(post)">
      Delete
    </span>

我的 console.log 写入 null,没有任何内容被删除。非常感谢我能得到的所有帮助,因为我很困!

【问题讨论】:

    标签: angularjs node.js mongodb mean-stack


    【解决方案1】:

    你应该有:

    _id : req.params.post
    

    代替:

    _id : req.params.id
    

    因为你在路由中有:post 参数:

    router.delete('/posts/:post', function(req, res, next) {
    

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-09
      • 2017-05-22
      相关资源
      最近更新 更多