2012-02-05 24 views
0

我有一個關於flex 4 remoteObjects的快速問題。 我想通過amfphp從MySql DB獲取信息到Flex 4.5。 我正在使用remoteobject標籤。我想使用結果屬性,但它似乎不適用於我。我究竟做錯了什麼?如何從remoteobject檢索結果AMFPHP Flex 4.5

如果我收集的信息形式數據庫沒有resulthandler它工作正常,但是當我想收集信息在arraycollection它不起作用。 arraycollection永遠不會充滿我檢索的信息。

This Works;

<?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我revieve陣列不ArrayCollection。

回答

1

amfPHP不返回結果作爲ArrayCollection,而是返回一個數組。把這一部分弄清楚,做得很好。

這裏是一些代碼的鏈接,這些代碼真的幫助了我。它從基本的字符串開始,然後是對象然後是數組(對象)。

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

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); 

希望它可以幫助