2011-11-11 75 views
0

我有一种情况必须简单解决,我猜想。当然人正在使用骨干关系与CoffeeScript的有...错误破坏用Coffeescript生成的骨干关系模型

这里有一个模式,我有:

class MyCompany.Models.Establishment extends Backbone.RelationalModel 
    defaults: 
    name: null 

class MyCompany.Collections.EstablishmentsCollection extends Backbone.Collection 
    model: MyCompany.Models.Establishment 
    url: '/establishments' 

我还没有添加任何关系呢,只是延长RelationalModel。现在,通过控制台时,我发出了一个摧毁它成功地破坏了服务器模型上的模型的实例,但完全失败时与跟踪:

Uncaught TypeError: Object #<Establishment> has no method 'getCollection' 
    _.extend.unregister 
    Backbone.Events.trigger 
    Backbone.RelationalModel.Backbone.Model.extend.trigger 
    _.extend.destroy.options.success 
    jQuery.extend._Deferred.deferred.resolveWith 
    done 
    jQuery.ajaxTransport.send.callback 

它死在骨干关系的235线。 js 0.4.0,因为“this”是我想的模型,而不是它应该是的,模型没有“getCollection”方法。

任何想法我做错了,或者我应该报告错误?作为参考,这里的Javascript咖啡生成:

(function() { 
    var __hasProp = Object.prototype.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; 
    }; 
    MyCompany.Models.Establishment = (function() { 
    __extends(Establishment, Backbone.RelationalModel); 
    function Establishment() { 
     Establishment.__super__.constructor.apply(this, arguments); 
    } 
    Establishment.prototype.defaults = { 
     name: null 
    }; 
    return Establishment; 
    })(); 
    MyCompany.Collections.EstablishmentsCollection = (function() { 
    __extends(EstablishmentsCollection, Backbone.Collection); 
    function EstablishmentsCollection() { 
     EstablishmentsCollection.__super__.constructor.apply(this, arguments); 
    } 
    EstablishmentsCollection.prototype.model = MyCompany.Models.Establishment; 
    EstablishmentsCollection.prototype.url = '/establishments'; 
    return EstablishmentsCollection; 
    })(); 
}).call(this); 
+0

您使用什么命令从控制台销毁模型? –

+0

just model.destroy() – Tony

回答

1

您需要更新底层的Backbone.js版本。原因如下:

当调用unregister时,您的错误来自this,该值错误。 unregister被称为响应于来自register结合的事件:

model.bind('destroy', this.unregister, this); 

即第三个参数集的上下文。但是该功能只是在Backbone 0.5.2最近添加的,如changelog所示。

+0

处理此问题。我刚刚升级到0.5.3,但它似乎仍在发生。我试图追踪并确保一切都设置正确。 – Tony

+0

我需要清除Rails缓存并重新启动pow。我在某处找到了一些旧东西。似乎现在正在工作。感谢您为我追踪Trevor。 – Tony