fetch()不调用其Success和Error回调函数(backbone.js)



我在$.post()的回调函数中有一个fetch()fetch()从后端获取数据并很好地更新集合,但是当它运行successerror回调时,什么都不会发生!我在它的两个回调中都放置了console.log(),它们从未出现在Javascript控制台中。

知道发生了什么事吗?

视图中的方法

create_set: function() {
    var self = this;
    // Post data to server
    $.post('api/create_set', {
        user_id: $('#user_id').val(),
        post_id: this.post_id,
        set_name: $('#new_set_name').val()
    }, function() {
        // Update list of Sets
        self.setList.fetch({
            data: {
                user_id: $('#user_id').val(),
                post_id: this.post_id
            },
            processData: true
        }, {
            success: function() {
                // Highlight the first class in list
                $(self.setListView.el).children('div:first').addClass('active');
                console.log('success'); // DOESNT RUN!
            }
        }, {
            error: function() {
                console.log('error');  // DOESNT RUN!
            }
        });
        console.log('hello');  // RUNS!
    });
}

successerror应该是传递给fetchoptions对象的属性,不必为它们创建单独的对象:

self.setList.fetch({
  data: {...},
  processData: true,
  success: function(){...},
  error: function(){...}
})

最新更新