Flex 将 XML 上传到数据网格/数据库

发布于 2024-09-28 08:59:46 字数 2736 浏览 10 评论 0 原文

我们的项目中有一个需求,要浏览&上传 XML 文件并将其显示在数据网格上,编辑网格,然后将内容保存到数据库中。我可以看到从特定文件夹获取 XML 并显示在数据网格上的示例,但看不到任何浏览 XML 然后上传它的示例。如果有人能给我指出示例或一些示例代码,那就太好了。我们的 XML 如下所示:

<VisitImportList>
    <Visit>
        <AuditDetails>
            <UpdateUser>ADMIN</UpdateUser>
            <UpdateTimestamp>2010-10-22T16:25:26.593Z</UpdateTimestamp>
        </AuditDetails>
        <VisitId>3</VisitId>
        <MeasurementCollectionId>4</MeasurementCollectionId>
        <WeightConfirmationCode>5</WeightConfirmationCode>
        <PrefilledIndicator>true</PrefilledIndicator>
        <VisitDate>2010-10-22T16:25:26.593Z</VisitDate>     
    </Visit>
    <Visit>
        <AuditDetails>
            <UpdateUser>ADMIN</UpdateUser>
            <UpdateTimestamp>2010-10-22T16:25:26.593Z</UpdateTimestamp>
        </AuditDetails>
        <VisitId>3</VisitId>
        <MeasurementCollectionId>3</MeasurementCollectionId>
        <BloodPressureConfirmationCode>4</BloodPressureConfirmationCode>
        <PrefilledIndicator>true</PrefilledIndicator>
        <VisitInvalidCode>1</VisitInvalidCode>
        <VisitInvalidReasonText>No Dates</VisitInvalidReasonText>
    </Visit>
</VisitImportList>

好的,我已经能够使用用于上传的 FileReference 和 XML/XMLListCollection 在网格上显示数据。现在的问题是当我尝试保存到数据库时。我不想创建一个新线程,所以我在这里添加了我的问题:

private function saveVisit(event:MouseEvent): void
            {
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();
                var data:Object = decoder.decodeXML(xmlDoc);

                var array:Array = ArrayUtil.toArray(data.VisitImportList.Visit);
                tempCollection = new ArrayCollection(array);

现在我的数组集合(tempCollection)中有数据。但它包含通用对象,我需要将它们转换为访问对象。所以我想循环遍历 ArrayCollection,将对象转换为特定的自定义访问对象,然后将它们添加到另一个集合(我确信这不是正确的方法,但我无法想出一个替代):

     for (var i:int = 0; i < tempCollection.length; ++i) 
                        {               
                            model.visit = new Visit();  
                            model.visit = Visit(tempCollection.getItemAt(i, 0)); // This line gives the error Type Coercion failed: cannot convert Object@1d4e4719 to com.model.Visit.
                            model.visit = tempCollection.getItemAt(i) as Visit; // This line always has Visit as null eventhough the tempCollection has 2 objects

model.pvList.visits.addItemAt(Visit, i);
}

所以有人可以帮助如何循环遍历 ArraCollection 并将 AS 对象转换为自定义 Visit 对象,然后添加到另一个 ArrayCollection 或更简单的方法来执行此操作,

谢谢

Harish

We have an requirement in our project to browse & upload an XML file and show it on the datagrid, edit the grid and then save the contents to the database. I'm able to see examples that take a XML from a specific folder and show on the datagrid, but not able to see any examples that browse for a XML and then upload it. It would be great if someone can point me to the examples or some sample code. Our XML looks like:

<VisitImportList>
    <Visit>
        <AuditDetails>
            <UpdateUser>ADMIN</UpdateUser>
            <UpdateTimestamp>2010-10-22T16:25:26.593Z</UpdateTimestamp>
        </AuditDetails>
        <VisitId>3</VisitId>
        <MeasurementCollectionId>4</MeasurementCollectionId>
        <WeightConfirmationCode>5</WeightConfirmationCode>
        <PrefilledIndicator>true</PrefilledIndicator>
        <VisitDate>2010-10-22T16:25:26.593Z</VisitDate>     
    </Visit>
    <Visit>
        <AuditDetails>
            <UpdateUser>ADMIN</UpdateUser>
            <UpdateTimestamp>2010-10-22T16:25:26.593Z</UpdateTimestamp>
        </AuditDetails>
        <VisitId>3</VisitId>
        <MeasurementCollectionId>3</MeasurementCollectionId>
        <BloodPressureConfirmationCode>4</BloodPressureConfirmationCode>
        <PrefilledIndicator>true</PrefilledIndicator>
        <VisitInvalidCode>1</VisitInvalidCode>
        <VisitInvalidReasonText>No Dates</VisitInvalidReasonText>
    </Visit>
</VisitImportList>

Ok I have been able to show the data on the grid using FileReference for upload and XML/XMLListCollection. Now the issue is when I try to save to the database. I did not want to create a new thread, so I have added my question to here:

private function saveVisit(event:MouseEvent): void
            {
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();
                var data:Object = decoder.decodeXML(xmlDoc);

                var array:Array = ArrayUtil.toArray(data.VisitImportList.Visit);
                tempCollection = new ArrayCollection(array);

Now I have the data in my arraycollection (tempCollection). But it holds generic objects and I need to convert them to Visit Object. So I want to loop through the ArrayCollection, convert the object in to specific custom Visit Objects and then add them to another Collection (I'm sure this is not the right way to do, but I'm not able to come up with an alternate):

     for (var i:int = 0; i < tempCollection.length; ++i) 
                        {               
                            model.visit = new Visit();  
                            model.visit = Visit(tempCollection.getItemAt(i, 0)); // This line gives the error Type Coercion failed: cannot convert Object@1d4e4719 to com.model.Visit.
                            model.visit = tempCollection.getItemAt(i) as Visit; // This line always has Visit as null eventhough the tempCollection has 2 objects

model.pvList.visits.addItemAt(Visit, i);
}

So can someone help on how to loop through the ArraCollection and convert the AS Object to custom Visit object and then add to another ArrayCollection OR an easier way to do this

Thanks

Harish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

影子是时光的心 2024-10-05 08:59:46

如果您使用 AIR 应用程序,则可以使用 Flex 中的 File 和 FileStream 对象轻松访问计算机中的资源。

http://livedocs.adobe.com/flex/3 /html/help.html?content=Filesystem_16.html

获取 XML 对象,然后从其项目命令将其转换为 XMLListCollection,即将

var xmlProvider:XMLListCollection = new XMLListCollection(xml.Visit);

此提供程序设置为您的数据网格并编写脚本以按照您的方式上传和保存此数据想。

但如果您正在编写 Web 应用程序。您无法访问不在客户端上的 Flex 临时文件路径中的资源。或者您必须使用“”。在这种情况下,相同的 AIR api 应该可以工作。

但是,如果您也不希望这样做,那么显然您必须将文件上传到服务器上,在客户端使用 HTTPService 读取该对象,创建 XMLListCollection 对象并将数据加载到 DataGrid 中。这将有助于

  1. 上传文件
  2. XML 文件的 HTTP 服务 + DataGrid 示例在服务器上

If you are working with AIR application, you can easily access resources in your computer using File and FileStream objects in Flex.

http://livedocs.adobe.com/flex/3/html/help.html?content=Filesystem_16.html

Get the XML object and then convert it to XMLListCollection from its item command i.e.

var xmlProvider:XMLListCollection = new XMLListCollection(xml.Visit);

Set this provider to your data grid and write script to upload and save this data the way you want.

But instead if you are writing web application. You can't access resources that are not in your flex temp files path on your client. Or you have to give flex access to the folder/file on client machine using "Global Security Settings". In this case same AIR api should work.

However, if you don't want that either then obviously you have to upload the file on server, read that object using HTTPService back at the client, create XMLListCollection object and load the data in DataGrid. This would help

  1. Upload File
  2. HTTP Service + DataGrid Sample for XML file on server
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文