作者pankk (KK)
看板Flash
标题[问题] 取得object array里的child object
时间Tue Dec 9 22:52:02 2008
请问一下各位,
我在flex下,
创造了一个object,
public var objData:Object ={children: [
{label: "a", children: [
{label: "a-1", children: [
{label: "a-1-1", nodeURL: "
http://a-1-1"},
]},
{label: "a-2", children: [
{label: "a-2-1", nodeURL: "
http://a-2-1"},
]},
]},
{label: "b", children: [
{label: "b-1", children: [
{label: "b-1-1", nodeURL: "
http://b-1-1"},
]},
{label: "a-2", children: [
{label: "b-2-1", nodeURL: "
http://b-2-1"},
]},
]},
]};
我设了一个<mx:Tree id="tree">来呈现上面的资料,
可是我想一开始进入页面tree就开启a-1这个node(用expandItem function),
tree.expandItem(objData.children[0], true, true);
上面那行objData.children[0]他会顺利开启 a node,
但是当我改成objData.children[0].children[0]时它却没反应,
我在想可能是我对as3的array里的观念不甚了解的关系,
想请问有经验的人这大概是什麽地方错了?
================================================
无意间看到这段 囧
Opens or closes a branch item. When a branch item opens, it restores the open
and closed states of its child branches if they were already opened. If you
set dataProvider and then immediately call expandItem() you may not see the
correct behavior. You should either wait for the component to validate or
call validateNow().
修改之後
private function initTree():void {
tree.expandItem(objData.children[0], true, true);
setTimeout(validateNow, 600);
setTimeout(openChildren, 600);
}
private function openChildren():void {
tree.expandItem(objData.children[0].children[0], true, true);
}
tree的初始化使用两次expandItem第一次太快会看不出效果,
所以改成这样让它看起来像它自动开了两次,
感谢兔兔凯特引导 XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.64.251.74
※ 编辑: pankk 来自: 210.64.251.74 (12/09 22:53)
1F:推 cjcat2266:objData.children[0].children[0]的确是a-1这个node没错 12/10 01:32
2F:→ cjcat2266:所以问题可能是在於Tree的method使用方面 12/10 01:33
3F:→ cjcat2266:不过我对Flex不熟...就有待Flex高手来详细回答罗 :) 12/10 01:33
4F:→ pankk:嗯嗯,我再从tree的相关下手好了 感谢 12/10 07:08
5F:→ pankk:try出来了,果然是tree的expandItem function的问题 12/10 08:58
6F:→ pankk:当我手动点开a node时发现里面的a-1 node是开的= =||| 12/10 09:01
※ 编辑: pankk 来自: 210.64.251.74 (12/10 09:38)