Flexible use of openitems in flex to implement tree refreshes after opening the original node

Source: Internet
Author: User

Law One: (directly using Openitems)

<?xml version= "1.0" encoding= "Utf-8"?> <mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" layout= " Vertical "initialize=" inittree () "Viewsourceurl=" srcview/index.html "> <mx:Script> <!--[cdata[[Bindable] ] public var open:object=new Object (); [Bindable] public var refreshdata:boolean=false; [Bindable] public var switchobj:object=new Object (); [Bindable] public var firstobj:object=new Object (); [Bindable] public var firstobj1:object=new Object (); [Bindable] public var firstobj2:object=new Object (); [Bindable] public var firstobj3:object=new Object (); [Bindable] public var provider:string= "Firstobj"; Private Function Inittree (): void {firstobj=new Object (); firstobj.label= "Foods"; firstobj.children=new Array (); Firstobj1.label= "Fruits"; Firstobj1.children=new Array (); Firstobj2.label= "oranges"; Firstobj1.children[0]=firstobj2; Firstobj.children[0]=firstobj1; Public Function Changeprovider (): void {open=sampletree.openitems; refreshdata=true; if (Provider = = "fiRstobj ") {firstobj3.label=" XXXX "; firstobj.children[1]=firstobj3; switchobj=firstobj; provider=" SWITCHOBJ "; Sampletree.dataprovider=switchobj; } else {firstobj3.label= "YYYY"; firstobj.children[1]=firstobj3; provider= "Firstobj"; Sampletree.dataprovider=firstobj; } rendertree (); Public Function Rendertree (): void {if (refreshdata) {sampletree.invalidatelist (); refreshdata=false; Sampletree.openitems=open; Sampletree.validatenow (); }}]]--> </mx:Script> <mx:tree id= "Sampletree" width= "+" dataprovider= "{firstobj}" labelfield= "label"/ > <mx:button label= "Change Data Provider" click= "Changeprovider ()"/> </mx:Application>

Law II: (Indirect use of openitems)

The idea is as follows: 1, first get the node that is opened in the tree, 2, according to the open node to judge, when the open node is empty, open the root directory, if the open node is not empty, then open the node into an array, and then call Openitems to implement the opening of the node. The approximate code is as follows: var openorg:array = typetree.openitems as Array; Typetree.invalidatelist (); Typetree.validatenow (); Keep open if (openorg.length = = 0) {typetree.selectedindex = 0; var root:xml = Typetree.selecteditem as XML; typetree.expa Nditem (Root, true); }else {var open:array = new Array (); for each (Var node:xml in openorg) {if (node) {node = Parsexmlutil.getfolderxmlbyid ( node. @id, Typexml);//Get Nodes Open.push from the tree; }} typetree.openitems = open;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.