开发者

Error in getting values from XML file to array Collection in Flex

I am trying display values in a datagrid in my application. I have all the values as an xml file. I had only one set of record n the XML file, to fill only one row of the data grid. While trying to store the values from the XML file to an Array Collection in the application File using the code, i.e.,

<mx:Model id="reviewList" source="assets/reviewList.xml"/>
<mx:ArrayCollection id="reviewlist" source="{reviewList.Item}"/> 

I get an error, saying

Error No# 1034: Type coercion failed cannot convert mx.utils::ObjectProxy to Array.

But If I have two record sets in the XML file, it works fine. If there is only one set, I get the above said error? What is the problem in this case?

Here is my xml file:

<ReviewList>
<Item>
    <ReviewId>1123</ReviewId>
    <TaskType>User Requirement Specification</TaskType>
    <RequestId>1223</RequestId>
    <ItemCodeVersion>URS - 1</ItemCodeVersion>
    <ReviewStartDate>29-Sep-2009</ReviewStartDate>
    <Status>Review In Progress</Status>
    <Reviewer>MR.RISHU GHOSE</Reviewer>
    <OpenDefect>0</OpenDefect>
    <CasualAnalysisPending>0</CasualAnalysisPending>
    <CloseDefects>0</CloseDefects>
    <VerifiedDefects>0</VerifiedDefects>
</Item>

</ReviewList>

And this is the datagrid where I want the details to be displayed.

<mx:DataGrid id="reviewDG" dataProvider="{reviewlist}" variableRowHeight="true" width="100%" height="200" 
                     horizontalScrollPolicy="off">

<mx:columns>
    <mx:DataGridColumn headerText="Review Id" dataField="ReviewId" textAlign="center" />

    <mx:DataGridColumn headerText="Task Type" dataField="TaskType" textAlign="center"/> 

    <mx:DataGridColumn headerText="Request Id" dataField="RequestId" textAlign="center"/> 

    <mx:DataGridColumn headerText="Item Code-Ver" dataField="ItemCodeVersion" textAlign="center" headerWordWrap="true"/> 

    <mx:DataGridColumn headerText="Review Start Date" dataField="ReviewStartDate" textAlign="center" headerWordWrap="true"/>

    <mx:DataGridColumn headerText="Status" dataField="Status" textAlign="center"/>

    <mx:D开发者_开发技巧ataGridColumn headerText="Reviewer" dataField="Reviewer" textAlign="center"/>

    <mx:DataGridColumn headerText="Open Defect" dataField="OpenDefect" textAlign="center" headerWordWrap="true"/> 

    <mx:DataGridColumn headerText="Casual Analysis Pending" dataField="CasualAnalysisPending" textAlign="center" headerWordWrap="true"/>

    <mx:DataGridColumn headerText="Close Defects" dataField="CloseDefects" textAlign="center" headerWordWrap="true"/>

    <mx:DataGridColumn headerText="Verified Defects" dataField="VerifiedDefects" textAlign="center" headerWordWrap="true"/>

    <mx:DataGridColumn headerText="Review Details" dataField="ReviewDetails" width="65" headerWordWrap="true"> 
     <mx:itemRenderer> 
       <mx:Component> 
        <mx:Label text="View" click="outerDocument.onViewClick()"/> 
       </mx:Component> 
     </mx:itemRenderer> 
    </mx:DataGridColumn> 


</mx:columns>
  </mx:DataGrid>    

There may be cases in my application where i need only one record to be displayed in the datagrid. In such cases how do I resolve this error?


My understanding is that the <mx:Model> declaration should probably be instead. Honestly never used either, but from my reading here it seems that the mx:Model declaration turns the xml into an object (ObjectProxy). So based on your problem, I'm guessing that if it encounters a single "Item", it turns that into a key:value pair (e.g., simple Object) within the proxy. When it encounters multiple "Item"s, it puts them into an Array instead. That is, the structure of the contents is likely unpredictable.

So if you use mx:XML (with format="e4x"),and use an XMLListCollection instead of ArrayCollection, you can use {reviewList.Item} as your source.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜