简体   繁体   中英

Flex: Cannot get value in array collection

I have an array collection object 'invArrayCol' which holds some data. I also have a datagrid. I have set dataProvider as invArrayCol.I displays the data properly when i use it with data grid. But the same invArrayCol shows null when used anywhere other than datagrid. I wrote this code

protected function titlewindow1_creationCompleteHandler(event:FlexEvent):void
{
    Cgt=new CgtSRObject();

    var autoobj:CSAutoNumberType=new CSAutoNumberType();
    autoobj.addEventListener(ResultEvent.RESULT,getInvNubmer);
    autoobj.getInvNo(invoiceType);

    trace(robj.salesPerson_Id);     

    getSalesReturnCgt.token=csInvoicePrint.getCgtData(robj.receive_Id);
    getSalesReturnCgt.addEventListener(ResultEvent.RESULT,getInvArrList);
    trace(Cgt.sr_no);

    datagrid_dataprovider=new ArrayCollection();
    datagrid_dataprovider=invArrayCol;
    calculateTotal();
}

This 2 lines set data to invArrayCol

getSalesReturnCgt.token=csInvoicePrint.getCgtData(robj.receive_Id);
getSalesReturnCgt.addEventListener(ResultEvent.RESULT,getInvArrList);

But here it gives value of invArrayCol as null.

datagrid_dataprovider=new ArrayCollection();
datagrid_dataprovider=invArrayCol;

Please tell me some way out of this.

The ResultEvent's result may return an ObjectProxy, in case the data is of length 1. Casting via 'as' would lead to a silent failing of the cast. So simply checking the type of the result would let you determine if the result can be used directly or if you have to wrap an ArrayCollection around it.

// This happens asynchronously, should have no effect in the function
getSalesReturnCgt.addEventListener(ResultEvent.RESULT,getInvArrList);

Also, the

// datagrid_dataprovider=new ArrayCollection(); // This line is obsoloete
datagrid_dataprovider=invArrayCol; // invArrayCol will get its value later

So, it looks like your expectation is for some code to have it executed synchronously, but it is always working asynchronously.

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