数组为空,即使它已在附加中设置

时间:2016-08-09 15:20:35

标签: dart dart-polymer

我有以下代码:

Grid get _gridA => $['myGridA'];
Grid get _gridB => $['myGridB'];
Grid get _gridC => $['myGridC'];
List<Grid> _grids = [];
Grid _selectedGrid = null;

attached(){
  // Sets array and sets the defaul selected Grid.
  _grids = [_gridA, _gridB, _gridC];
  _selectedGrid = _grids[0];
}

onTabChange(index, _){
 //crashes here, because at this point, _grids is still [] and not [a,b,c]
  _selectedGrid = _grids[index];
}

有没有办法解决这个问题? set也没有做任何事情。 当我尝试在我将其定义为[]的顶部实例化时,我会得到错误,我的数组中不能包含非静态项。

0 个答案:

没有答案