如何从远程对象检索结果 AMFPHP Flex 4.5
我有一个关于 Flex 4 RemoteObjects 的简单问题。 我想通过 amfphp 从 MySql DB 检索信息到 Flex 4.5。 我正在使用远程对象标签。我想使用结果属性,但它似乎对我不起作用。我做错了什么?
如果我在没有结果处理程序的情况下从数据库收集信息,它可以正常工作,但是当我想在数组集合中收集信息时,它就不起作用。 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。
I have a quick question about flex 4 remoteObjects.
I would like to retrieve information from a MySql DB via amfphp to Flex 4.5.
I'm using a remoteobject tag. I would like to use the result attribute but it doesn't seem to work for me. What am i doing wrong?
If i collect the information form the DB without a resulthandler it works fine, but when i would like to collect the informatie in an arraycollection it doesn't work. The arraycollection never gets filled with the information i retrieve.
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>
and this doens't work.
<?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>
what am i doing wrong? can anybody help met out on this one? i have tried it with both the spark and the mx datagrid.
Well i have found the solution. From Php i revieve an Array not an ArrayCollection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
amfPHP 不以 ArrayCollection 形式返回结果,而是以 Array 形式返回结果。很好地解决了这部分问题。
这是一些对我真正有帮助的代码的链接。它从基本字符串开始,然后是对象,然后是(对象的)数组。
http://www.brentknigge.com/?q=node/499
amfPHP doesn't return results as an ArrayCollection, but rather an Array. Well done on figuring that part out.
Here is a link to some code that really helped me. It starts off with basic strings, then objects then array (of objects).
http://www.brentknigge.com/?q=node/499
这是因为您要将数组分配给数组集合。
如果没有 php 函数的洞察力,很难准确回答。如果您的 php 服务返回类似这样的内容:
您可以将其放入这样的数组集合中:
希望它有帮助
This is because you are assigning an array to an array collection.
it's tough to answer accurately without having your php function insight. If your php service is returning something like this:
you can put it in an array collection like this:
Hope it helps