[問題] 取得object array裡的child object
請問一下各位,
我在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)
推
12/10 01:32, , 1F
12/10 01:32, 1F
→
12/10 01:33, , 2F
12/10 01:33, 2F
→
12/10 01:33, , 3F
12/10 01:33, 3F
→
12/10 07:08, , 4F
12/10 07:08, 4F
→
12/10 08:58, , 5F
12/10 08:58, 5F
→
12/10 09:01, , 6F
12/10 09:01, 6F
※ 編輯: pankk 來自: 210.64.251.74 (12/10 09:38)