Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我创建一个模型并且现在要删除时,Backbone.js_Backbone.js_Chaplinjs - Fatal编程技术网

当我创建一个模型并且现在要删除时,Backbone.js

当我创建一个模型并且现在要删除时,Backbone.js,backbone.js,chaplinjs,Backbone.js,Chaplinjs,我的服务器端有express.js和mongodb,前面有brunch和chaplin.js,我的问题是当我创建一个模型时,它会出现在模型列表中,但我不能删除它,因为方法isNew()返回true 我认为这是服务器端的问题,不是吗 这是密码 评论\u视图。咖啡 View = require 'views/base/view' template = require 'views/templates/comment' mediator = require 'mediator' module.exp

我的服务器端有express.js和mongodb,前面有brunch和chaplin.js,我的问题是当我创建一个模型时,它会出现在模型列表中,但我不能删除它,因为方法isNew()返回true

我认为这是服务器端的问题,不是吗

这是密码

评论\u视图。咖啡

View = require 'views/base/view'
template = require 'views/templates/comment'
mediator = require 'mediator'

module.exports = class CommentView extends View
  template: template
  autoRender: true
  container: '.list-comment'
  tagName: 'li'

  initialize: ->
    @delegate 'click', '.icon-remove', @remove_one

  remove_one: ->
    @model.destroy()
    @remove()
server.js

app.delete('/api/comments/:id',function(req, res) {
  CommentsEventModel.findByIdAndRemove(req.params.id, function (err, comments) {
    if (err) { throw err; }
    res.send(200);
  });
});
如果
model.isNew()
返回
true
是因为
model.id
null


尝试检查您的服务器如何响应
CREATE
动词,以及它是否使用包含
id
字段的正确JSON格式进行响应。

您的问题是(a)您无法“删除”客户端创建的模型,但尚未保留到服务器,或者(b)从服务器上取下的模型注册为
IsNew()
,因此对
Destroy()
的调用不会导致对服务器的Ajax调用(因此该模型不会从Mongo中删除)?我认为CREATE动词不正确,因为我没有返回JSON。返回一个JSON,其中至少包含此模型的全新
id
。尝试将
id
属性命名为
id
,而不是
event\u id
。我可以这样做,因为注释返回模型的JSON对象。