0

我有一个关于 flex 4 remoteObjects 的快速问题。我想通过 amfphp 从 MySql DB 检索信息到 Flex 4.5。我正在使用远程对象标签。我想使用结果属性,但它似乎对我不起作用。我究竟做错了什么?

如果我在没有结果处理程序的情况下从数据库中收集信息,它可以正常工作,但是当我想在 arraycollection 中收集信息时它不起作用。arraycollection 永远不会被我检索到的信息填充。

这行得通;

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600"
           creationComplete="initApp()">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <mx:RemoteObject id="myRemote" 
                     destination="solicitantService" 
                     source="resume.solicitantService"   
                     endpoint="http://localhost:8181/amfphp/gateway.php"/>
</fx:Declarations>

<fx:Script>
    <![CDATA[

        private function initApp():void
        {
            myRemote.getUsers();
        }

    ]]>
</fx:Script>

<mx:DataGrid id="myGrid" dataProvider="{myRemote.getUsers.lastResult}"/>    
</s:Application>

这不起作用。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600"
           creationComplete="initApp()">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <mx:RemoteObject id="myRemote" 
                     destination="solicitantService" 
                     source="resume.solicitantService"   
                     endpoint="http://localhost:8181/amfphp/gateway.php"
                     result="myRemote_resultHandler(event)"/>
</fx:Declarations>


<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.rpc.events.ResultEvent;

        [Bindable]
        private var users:ArrayCollection = new ArrayCollection();


        private function initApp():void
        {
            myRemote.getUsers();
        }

        protected function myRemote_resultHandler(event:ResultEvent):void
        {
            users = event.result as ArrayCollection;
        }

    ]]>
</fx:Script>

<mx:DataGrid id="myGrid" dataProvider="{users}"/>
</s:Application>

我究竟做错了什么?有人可以帮忙解决这个问题吗?我已经用 spark 和 mx datagrid 试过了。

好吧,我找到了解决方案。从 PHP 中,我获得了一个数组而不是 ArrayCollection。

4

2 回答 2

1

amfPHP 不会以 ArrayCollection 的形式返回结果,而是以 Array 形式返回结果。搞清楚那部分做得很好。

这是一些真正帮助我的代码的链接。它从基本字符串开始,然后是对象,然后是(对象的)数组。

http://www.brentknigge.com/?q=node/499

于 2013-01-27T04:24:14.380 回答
0

这是因为您将数组分配给数组集合。

如果没有您的 php 函数洞察力,很难准确回答。如果您的 php 服务返回如下内容:

$outputArray['users'] = myUsers(); //here myUsers() is a function which is doing the query and fetching the results

你可以把它放在这样的数组集合中:

var usersCollection:ArrayCollection = new ArrayCollection(event.result.usres);

希望能帮助到你

于 2013-10-10T17:59:01.707 回答