set dataprovider in actionscript
I have a datagrid w/ dataProvider property set in MXML as:
dataProvider="{pagedResult.lastResult}"
How do I set the dataprovider in actionscript? I have:
protected function getResult (event:FlexE开发者_运维问答vent):void
{
pagedResult.token = mydata.paged();
adg1.dataProvider = pagedResult.lastResult;
}
but I'm doing something wrong as it does not work
Your code looks solid, I guess the issue is that you need to convert it. You didn't say what sort of data your service is returning, but for the purposes of this sample I'll assume an Array
Try something like this
var myCollection : ArrayCollection = new ArrayCollection(pagedResult.lastResult as Array);
adg1.dataProvider = myCollection;
First if you are going to set the dataProvider from Actionscript I would remove the binding from the MXML, or you could just update the property that is bound but I do not know it's type so I will assume you have no problem removing the binding from the MXML tag.
Second as another answer mentioned you will want to convert your results to an ArrayCollection, you can find some useful functions in the mx.utils.ArrayUtil class.
Lastly it is important when working with large datasets you should update the ArrayCollection directly rather than always creating a new one. The list/datagrid will automatically redraw and update, optimally, without you having to worry about it as long as you add/remove/etc through your newly created ArrayCollection.
精彩评论