简体   繁体   中英

flex 3 and autoComplete

im trying to getting auto complete working and i can do so fine when i just create an array in my mxml and then just initialize an arrayCollection at the top of the file in the initialize keyword.

However i want to populate the arraycollection from a webservice but i cant seem to get it;

im my application tag i have the following

creationComplete="init()"
initialize="data2 = new ArrayCollection(data1);" 

then in my init method;

    private function init():void 
{
userRequest.loadWSDL(wsdlUrl);
userRequest.getAllCountries();
}   

//this is called when i get a result from userRequest.getAllCountries();

 private function getAllCountriesResult(e:ResultEvent):void 
    {
    data1 = new Array(e.result);
        }

however my text box is not getting any value.

Anyone with ideas?

first off, Array is not Bindable so changing the variable data1 will have no knock on effect.

The arrayCollection is bindable.

So presumming that the result (e.result) is actually an array (you should check this when debugging) then you could do the following

[Bindable]
priavte var ac : ArrayCollection;

then inside you're getAllCountriesResult function.

ac = new ArrayCollection(e.result);

then anything that has is dataprovider set to the var ac will be updated.

If you wish to update a text value inside a textArea or similar then you should listen for the change event in the arrayCollection and take the appropriate action then.


from your additional points below (just edit your original question)

I take it the autocomplete your talking about is the autocomplete text input box from adobe exchange area as a normal text box doesn't take an arrayCollection. If you posted some code it may make it easier to help you. Preinitialize, then initialize, then creationComplete, then applicationComplete (this is the order they get called in).

If your using the component I'm thinking of, check out http://www.websector.de/blog/2008/04/30/quick-tip-avoid-issues-using-adobes-autocomplete-input-component-using-flex-3/ It appears it may have some issues with flex 3, so check out http://blogs.adobe.com/flex/2006/09/component_autocomplete_text_in.html .

Try this:

private function getAllCountriesResult(e:ResultEvent):void 
{
   data2.source = new Array(e.result); // or data2.source = e.result as Array
}

Make sure data2 is already initialized as a ArrayCollection.

As for AutoComplete, I'm trying to work things out myself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM