Flex中在Tree綁定數(shù)據(jù)后自動展開樹節(jié)點的方法
更新時間:2014年01月28日 17:14:01 作者:
使用Tree組件在綁定數(shù)據(jù)后自動展開所有樹型節(jié)點(不需要用戶再自己點擊展開節(jié)點,會方 便許多),接下來為大家介紹下具體的實現(xiàn)
用Flex/Flash做開發(fā)的同志們應(yīng)該會使用 expandChildrenOf(item,true)方法來使用Tree組件在綁定數(shù)據(jù)后自動展開所有樹型節(jié)點(不需要用戶再自己點擊展開節(jié)點,會方 便許多),而在Flex開發(fā)幫忙文檔中很明確寫道:
"If you set dataProvider and then immediately call expandChildrenOf() you may not see the correct behavior. You should either wait for the component to validate or call the validateNow() method. "
第一種:(已驗證)
//全部展開,初始選中第一項
treePlayList.dataProvider=results;//刷新Tree的全部節(jié)點展開 - royanxin - royanxin的博客
treePlayList.validateNow(); //驗證并更新此對象的屬性和布局,并重繪該對象(如果需要)。
treePlayList.selectedIndex=0;
treePlayList.expandChildrenOf(treePlayList.selectedItem,true);//全部展開
第二種:
setTimeout(IniExpand, 1000); //延時1秒
private function IniExpand():void {
TreeView1.selectedIndex=1;
TreeView1.expandItem(TreeView1.selectedItem,true);
}
第三種:
//全部展開,初始未選中任何選項
sysTree.validateNow();
for each(var item:XML in this.sysTree.dataProvider){
sysTree.expandChildrenOf(item,true);
}
注意:
"If you set dataProvider and then immediately call expandChildrenOf() you may not see the correct behavior. You should either wait for the component to validate or call the validateNow() method. "
第一種:(已驗證)
復(fù)制代碼 代碼如下:
//全部展開,初始選中第一項
treePlayList.dataProvider=results;//刷新Tree的全部節(jié)點展開 - royanxin - royanxin的博客
treePlayList.validateNow(); //驗證并更新此對象的屬性和布局,并重繪該對象(如果需要)。
treePlayList.selectedIndex=0;
treePlayList.expandChildrenOf(treePlayList.selectedItem,true);//全部展開
第二種:
復(fù)制代碼 代碼如下:
setTimeout(IniExpand, 1000); //延時1秒
private function IniExpand():void {
TreeView1.selectedIndex=1;
TreeView1.expandItem(TreeView1.selectedItem,true);
}
第三種:
復(fù)制代碼 代碼如下:
//全部展開,初始未選中任何選項
sysTree.validateNow();
for each(var item:XML in this.sysTree.dataProvider){
sysTree.expandChildrenOf(item,true);
}
注意:

相關(guān)文章
Flex4 使用itemRenderer 為Tree加線具體實現(xiàn)
本文為大家詳細介紹下Flex4如何使用itemRenderer 為Tree加線,感興趣的朋友可以參考下2013-12-12Flex 基于數(shù)據(jù)源的Menu Tree實現(xiàn)代碼
由外部參數(shù)flashvars指定數(shù)據(jù)源的文件位置或render鏈接,在源數(shù)據(jù)上加href和target屬性來控制打開窗口,可自定義父節(jié)點和子節(jié)點圖標,不設(shè)置采用系統(tǒng)默認,感興趣的你可以了解下啊,或許對你有所幫助2013-01-01flex的tree動態(tài)加載大量數(shù)據(jù)與滾動條相關(guān)問題探討
本文將對flex的tree動態(tài)加載大量數(shù)據(jù)與滾動條相關(guān)的問題進行探討,感興趣的朋友可以參考下哈,希望對你有所幫助2013-05-05