2013-10-18 36 views
1

我有一个很大的问题与烬。如果我导航到某处,我有时会收到错误Cannot set property 'type' of null,并且视图不会呈现。错误是在jQuery中引发的,而不是在Ember中。Ember - 无法设置null的属性'type'

我从来没有在我的应用程序中设置something.type。我不知道错误可能是什么。的路由+控制器+查看示例(不要忘了,它不会发生的每一次。)

路由:this.route("channels", {path: "/channels/:only"});

路线:

App.ChannelsRoute = Ember.Route.extend({ 
    model: function(params) { 
    var controller = this.controllerFor("channels"); 
    controller.set("only", params.only); 

    if (!controller.get("hasContent")) { 
     return controller.updateContent(); 
    } 
    } 
}); 

控制器:

App.ChannelsController = Ember.ArrayController.extend({ 

    sortProperties: ["position"], 
    sortAscending: true, 

    hasContent: function() { 
    return this.get("content").length > 0; 
    }.property("@each"), 

    channels_category: function() { 
    return this.get("only"); 
    }.property("only"), 

    filteredContent: function() { 
    var filterType = "group"; 
    var filterID = 1; 

    switch(this.get("only")) { 
     case "primary": filterType = "group"; filterID = 1; break; 
     case "secondary": filterType = "group"; filterID = 2; break; 
     case "regional": filterType = "group"; filterID = 3; break; 
     case "hd": filterType = "hd"; filterID = true; break; 
     default: filterType = "group"; filterID = 1; break; 
    } 

    return this.filterProperty(filterType, filterID); 
    }.property("@each", "only"), 

    updateContent: function() { 
    return $.getJSON(getAPIUrl("channels.json")).then(function(data){ 
     var channels = []; 
     $.each(data.channels, function() { 

     var channel = App.Channel.create({ 
      id: this.id, 
      name: this.name, 
      group: this.group, 
      hd: this.hd, 
      position: this.position, 
      recordable: this.recordable 
     }); 
     channels.pushObject(channel); 
     }); 

     return channels; 
    }); 
    } 
}); 

其发生在很多控制器中。我希望有人知道一个解决方案。

回答

0

你可以测试你的updateContent函数的这种变化吗?改变了渠道VAR到控制器模型...

updateContent: function() { 
    return $.getJSON(getAPIUrl("channels.json")).then(function(data){ 
     var channels = this.get('model'); 
     $.each(data.channels, function() { 

     var channel = App.Channel.create({ 
      id: this.id, 
      name: this.name, 
      group: this.group, 
      hd: this.hd, 
      position: this.position, 
      recordable: this.recordable 
     }); 
     channels.pushObject(channel); 
     }); 
    }); 
    } 
+0

感谢您的回答,是的,我会在星期一进行测试,并给出您的反馈! ;) –

+0

嗨,对于迟到的答案抱歉。我试了一下,如果我改变了路线,它的工作。但是如果我在这条路线上重新加载页面,那么应用程序永远在装载路径中搜索。控制台输出为空。我认为加载路线预计将在任何内容后返回。我不确定。 *编辑:*如果我添加'return [];'在updateContent结束时,它再次加载,但内容当然是空的。 –

0

如果它在jQuery的发生,它的发生或者在一个AJAX调用,或者你使用jQuery做一些DOM操作。您的最佳开始将是调用AJAX调用,并检查您使用的任何Handlebars助手(特别是如果您有任何已声明类型的input helpers)。

+0

Okey很高兴知道,我会创建一个小应用程序,看看它是否也在那里发生。我会在星期一尝试! –

相关问题