93 可读性
 将光标移到/点击文章中的句子上,可以查看译文。      显示繁体中文内容    显示简体中文内容

Uncaught TypeError: Cannot read property 'length' of null when moving out from a specific page
未捕获文件:从特定页面移出时无法读取属性'length'

In my Ember app i have a search page which is a complex page with many nested controller.

Only in that page, when i move out to any other page, i receive the error :

Uncaught TypeError: Cannot read property 'length' of null

And the next page is blank.the navbar remains, so if i move to another page, everything continue normally.

This is the router :

this.resource('products', function(){
 this.route('search');
});

This is routes/products/search.js :

import Ember from"ember";
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {});

The template contains 3 nested #each, any of them with a specific itemController :

{{#each subset in subsets itemController="products/search/subset"}}
 {{#each panel in subset.panels itemController="products/search/panel"}}
 {{#each value in panel.values itemController="products/search/value"}}

Every array is an array of Ember.Objects, like :

var Subset = Ember.Object.extend({
 panels: []
});
//
var Panel = Ember.Object.extend({
 values: []
});

I think that some callback is called when i change page and something during the cleaning of the controllers causes the error, but i really don't know how to find the error.i tried to debug using the console, but the error comes from vendor.js and nothing pointed me to a line in my files.

时间:原作者:1个回答

After a lot of debugging and different attempts, i found that the error was due to the wrong type of controller i used.

I defined the controllers as Ember.ArrayController.extend({});.

Changing to Ember.ObjectController.extend({}); resolved the error

原作者:
...