修改源文件中的getItemDepth方法,做如下改动:
protected function getItemDepth(item:Object, offset:int):int
{
var depth:int;
//if the dataprovider have a root, we begin from the root.
if (hasRoot)
{
depth = searchForCurrentDepth(_rootModel[0], item);
}
//If the dataprovider don't have a root, we need to parse all items from the first level.
else
{
var i:int = 0;
do
{
if (i == _rootModel.length) break;
depth = searchForCurrentDepth(_rootModel[i++], item);
} while (depth == -1)
}
if (depth == -1)
trace("item not found");
//throw new Error("item not found");
return depth;
}
主要是修改了红色标注的代码,绿色标识的部分可改可不改。不影响最终的结果
if (i == _rootModel.length) break;
修改这部分代码的原因是 第一层循环的次数最多不超过根节点的个数,如果超出,则跳出循环
trace("item not found");
不再抛出错误,而是打印错误语句,,,主要是查找item==null的节点深度时
这样修改代码后,TreeGrid的数据源重新赋值也不会出现错误了。
如何编译源代码,参考上一篇文章~~~