小编oz.*_*oz.的帖子

Backbone.js model.destroy()不发送DELETE请求

我已经尝试了几天才能使这个工作,我只是无法弄清楚为什么当我有我的视图来销毁一个属于一个集合的模型(它正确具有一个url属性,用于开始获取模型的数据),仅触发destroy'event',它被冒泡到集合中,以便通过我的列表视图轻松绑定.但它根本不会向服务器发送实际的DELETE请求或任何请求.在我看的每个地方,我看到每个人都使用集合的url attr,或者如果模型未连接到集合则使用urlRoot.我甚至在实际的this.model.destroy()之前测试了模型<console.log(this.model.url());

我没有覆盖主干的破坏和同步方法.此外,每个模型都有一个id属性,该属性通过集合的fetch(来自数据库记录)填充.

销毁发生在列表项视图中,集合的"destroy"事件绑定在列表视图中.一切运作良好(事件处理),但问题是,没有对服务器的请求.

我希望backbone.js会自动完成.这就是文档所暗示的,以及各处的众多例子.

非常感谢能够提供一些有用信息的人.

仅供参考:我正在开发wampserver PHP 5.3.4.

ListItemView = BaseView.extend({

    tagName: "li",

    className: "shipment",

    initialize: function (options) {
        _.bindAll(this);
        this.template = listItemTemplate;   
        this.templateEmpty = listItemTemplateEmpty;
    },  

    events: {
        'click .itemTag' : 'toggleData',
        'click select option' : 'chkShipper',
        'click .update' : 'update',
        'click button.delete' : 'removeItem'
    },  

    // ....

    removeItem: function() {
        debug.log('remove model');

        var id = this.model.id;

        debug.log(this.model.url());

        var options = {
            success: function(model, response) {
                debug.log('remove success');
                //debug.log(model);
                debug.log(response);
                // this.unbind();
                // this.remove();
            },
            error: function(model, response) …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax model backbone.js

14
推荐指数
1
解决办法
1万
查看次数

标签 统计

ajax ×1

backbone.js ×1

javascript ×1

model ×1

php ×1