在 Flex 中从 XML 文件获取值到数组集合时出错
我正在尝试在我的应用程序中的数据网格中显示值。我将所有值都保存为 xml 文件。 XML 文件中只有一组记录,仅填充数据网格的一行。当尝试使用代码将 XML 文件中的值存储到应用程序文件中的数组集合时,即,
<mx:Model id="reviewList" source="assets/reviewList.xml"/>
<mx:ArrayCollection id="reviewlist" source="{reviewList.Item}"/>
我收到错误,提示“
Error No# 1034: Type coercion failed cannot convert mx.utils::ObjectProxy to Array.
但是如果我在 XML 文件中有两个记录集,则它工作正常”。如果只有一套,我会收到上述错误吗?这个案例有什么问题呢?
这是我的 xml 文件:
<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>
这是我想要显示详细信息的数据网格。
<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:DataGridColumn 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>
在我的应用程序中,有时我只需要在数据网格中显示一条记录。在这种情况下我该如何解决这个错误?
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:DataGridColumn 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的理解是
声明可能应该是相反的。老实说,从来没有使用过,但从我的阅读这里 看来mx:Model
声明将 xml 转换为对象 (ObjectProxy)。因此,根据您的问题,我猜测如果它遇到单个“项目”,它会将其转换为代理内的键:值对(例如,简单的对象)。当它遇到多个“Item”时,它会将它们放入一个数组中。也就是说,内容的结构可能是不可预测的。因此,如果您使用 mx:XML(格式为“e4x”),并使用 XMLListCollection 而不是 ArrayCollection,则可以使用
{reviewList.Item}
作为源。My understanding is that the
<mx:Model>
declaration should probably be instead. Honestly never used either, but from my reading here it seems that themx: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.