我对 ember 有一个大问题。如果我导航到某个地方,Cannot set property 'type' of null
有时会出现错误,并且不会呈现视图。错误是在 jQuery 中引发的,而不是在 Ember 中。
我从未something.type
在我的应用程序中设置。我不知道错误可能是什么。Route + Controller + View 的示例(不要忘记,它不是每次都发生。)
路由: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;
});
}
});
它发生在很多控制器中。我希望有人知道解决方案。