我有一个很大的问题与烬。如果我导航到某处,我有时会收到错误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;
});
}
});
其发生在很多控制器中。我希望有人知道一个解决方案。
感谢您的回答,是的,我会在星期一进行测试,并给出您的反馈! ;) –
嗨,对于迟到的答案抱歉。我试了一下,如果我改变了路线,它的工作。但是如果我在这条路线上重新加载页面,那么应用程序永远在装载路径中搜索。控制台输出为空。我认为加载路线预计将在任何内容后返回。我不确定。 *编辑:*如果我添加'return [];'在updateContent结束时,它再次加载,但内容当然是空的。 –