我有一个关于flex 4 remoteObjects的快速问题。我想通过amfphp到Flex 4.5从MySql数据库中检索信息。我正在使用remoteobject标记。我想使用result属性,但它似乎对我不起作用。我做错了什么?
如果我在没有结果处理程序的情况下从数据库中收集信息,它可以正常工作,但当我想在数组集合中收集信息时,它就不起作用了。数组集合永远不会被我检索到的信息填满。
这是有效的;
<?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和mxdatagrid上都尝试过。
我找到了解决办法。从Php我审查了一个数组而不是数组集合。
amfHP不将结果作为ArrayCollection返回,而是作为Array返回。弄清楚那部分做得很好。
这里有一个链接,指向一些真正帮助过我的代码。它从基本字符串开始,然后是对象,然后是(对象的)数组。
http://www.brentknigge.com/?q=node/499
这是因为要将数组分配给数组集合。
如果不深入了解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);
希望它能帮助