2013-07-19 109 views
0

我想保存一個模型,我可以保存第一個模型罰款,但是如果我保存一個模型,然後另一個直 - 事後得到以下錯誤,骨幹 - 未捕獲TypeError:對象[對象對象]沒有方法'調用'

Uncaught TypeError: Object [object Object] has no method 'call'

什麼會導致此錯誤?

我保存的代碼如下所示,

GroupModalHeaderView.prototype.save = function(e) { 

    var $this = this; 
    this.collection = new app.GroupCollection(); 

    if(this.$("#group-name").val() !== "") { 
    this.collection.add(this.model,{ 
     merge: true 
    }); 
    } 

    this.model.save({ 
    name: this.$("#group-name").val(), 
    async: false, 
    wait: true 
    }, { 
    success: function() { 

     var GroupList = new app.GroupListView({ 
     model: $this.model, 
     collection: $this.collection 
     }); 

     var modal = new app.GroupModalView({ 
     model: $this.model, 
     collection: $this.collection 
     }); 

     $this.collection.on("change", GroupList.render(), this); 
     $this.collection.on("change", modal.render(), this); 
     //return $this.cancel(); 
    } 
    }); 
}; 

而且我的模型代碼看起來像這樣,

(function() { 
    var Group, GroupSearchModel, 
    __hasProp = {}.hasOwnProperty, 
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; 

    Group = (function(_super) { 

    __extends(Group, _super); 

    function Group() { 
     return Group.__super__.constructor.apply(this, arguments); 
    } 

    Group.prototype.urlRoot = config.base + "api/group/groups"; 

    Group.prototype.defaults = { 
     user_id: "", 
     name: "New Group", 
     email: "", 
     url: "", 
     telephone: "", 
     mobile: "", 
     fax: "", 
     people: "" 
    }; 

    Group.prototype.idAttribute = "id"; 

    return Group; 

    })(app.BaseModel); 

    GroupSearchModel = (function(_super) { 

    __extends(GroupSearchModel, _super); 

    function GroupSearchModel() { 
     return GroupSearchModel.__super__.constructor.apply(this, arguments); 
    } 

    return GroupSearchModel; 

    })(app.BaseModel); 

    this.app = window.app || {}; 

    this.app.Group = Group; 

    this.app.GroupSearchModel = GroupSearchModel; 

}).call(this); 

我假設是有事情做與.call(this)在結束我的模型?

+0

基於您的代碼,你真的需要閱讀這篇文章如何組織骨幹視圖和模型:http://alexkinnee.com/2013/12/optimal-use-of-backbone-js-model -events-and-mvc-structure/ :) –

回答

1

在你的代碼中有一堆拙劣的東西,但我的第一個猜測是這個錯誤導致了你當前的問題。綁定事件處理程序時,通常需要引用,但不是EXCUTE處理函數。因此,而不是GroupList.render()(帶括號)正在執行的功能,你想要GroupList.render(沒有括號) 只是引用它而不執行。

$this.collection.on("change", GroupList.render, this); 
$this.collection.on("change", modal.render, this); 
//return $this.cancel(); 
+0

謝謝,謝謝,謝謝。 :d – LowFieldTheory

相關問題