English 中文(简体)
Flex将XML上传到数据网格/数据库
原标题:Flex Upload XML to datagrid/database

我们的项目中有一个要求,即浏览&;上传一个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)中有了数据。但它包含通用对象,我需要将它们转换为Visit对象。因此,我想循环浏览ArrayCollection,将对象转换为特定的自定义访问对象,然后将它们添加到另一个Collection(我确信这不是正确的方法,但我无法想出替代方法):

     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中吗

谢谢

哈里什语

最佳回答

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

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

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

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

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

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

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

  1. Upload File
  2. HTTP Service + DataGrid Sample for XML file on server
问题回答

暂无回答




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签