2013-10-18 65 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很高興知道,我會創建一個小應用程序,看看它是否也在那裏發生。我會在星期一嘗試! –

相關問題