views:

1468

answers:

4

hi, i have a textinput field which has autoComplete, i populate its dataprovider from a webservice.

I assign the dataprovider with the result of a webservice call

ac.dataProvider = e.result;

however i now want to edit each field returned from the ResultEvent so i can add some more inforamtion, i tried doing some thing like this;

var results:ArrayCollection = new ArrayCollection(new Array(e.result));
var newResultsArray:ArrayCollection;
var array:Array = new Array;
for(var i:int = 0 ; i < results.length; i++)
{
   array[i] = results.getItemAt(i) + "extraInformation"; 
}
newResultsArray = new ArrayCollection(array);
acu.dataProvider = newResultsArray;

this however just cuases all results to apear in one field. Any suggestions on how to assign the edited data to my dataprovider in the same format that the result.event returns it?

the problem appears to be that the line containing

results.getItemAt(i) + "extraInformation";

is returning the complete contents of the call into one row.Is there any way to break this up so i can get each individual row from the ResultEvent?

A: 

it will all depend on what e.result is. I'm suspecting that it is some kind of object/xml and as such when you are making it into an array then into a arrayCollection it is only populating element 0 in the arrayCollection.

What I think you'll need to do is iterate through whatever e.result is and add each of its elements to an arrayCollection.

so for example if the e.result is XML then try the following

var xmlBack : XML = XML(e.result);
var xmllist : XMLList = new XMLList();
xmllist = xmlBack.nodeYourLookFor;
var results = new ArrayCollection();
for each(var xml : XML in xmllist ){
    results.addItem(xml.toString));
}

yourAutoComplete.dataProvider = results;

As I said it all depends on what the e.result is.

kenneth
A: 

its actually an object i get back,

when i debug and look at the contents of my webservice call its an arrayCollection. im new to Flex so this basic thing is still causing me problems!:)

combi001
string. so as in the above xmlBack.string, just make sure that its valid XML (enclose your e.g code snippet with a container node when sending it back in the result)
kenneth
how r u doing the webservice. make sure you've set the .resultFormat = "e4x"; if your returning XML.
kenneth
A: 

Got it sorted by doing the following;

var lengthOfResult:int = e.result.length;
var arrayCollResults:ArrayCollection = new ArrayCollection();
var resultArray:Array = new Array(e.result);
    for(var i:int = 0 ; i < lengthOfResult; i++){
 arrayCollResults.addItem(e.result[i] + additionalInfo);
}
ac.dataProvider = arrayCollResults;
combi001
A: 

From your question, it sounds like you want to leave the data (and its type) intact, which you should be able to within your event handler, without creating new collections, casting, etc. But kenneth is right -- it's hard to be specific without knowing the type and structure of your result.

Judging by your addendum, posted as I was responding, you should've been able to do this, since it looks like the result was an array:

for (var i:int = 0; i < e.result.length; i++)
{
    e.result[i] += newInformation;
}

var ac:ArrayCollection = new ArrayCollection(e.result);

... to alter the result data directly, and then create a new ArrayCollection from that. There's no major difference between what you came up with and this, though -- just wanted to illustrate how you could've modified the result data directly before casting or creating new objects from it.

Christian Nunciato