我有以下问题。如何在我的fx模型连接中选择一个php文件作为源文件。
我想在我的fx模型源中使用一个返回xml文件的php文件。这可能吗?
现在我尝试使用http服务在运行时读取php文件并使用xmllistcollection。这是我的代码:
<?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"
xmlns:components="components.*">
<s:layout>
<s:VerticalLayout paddingTop="20" gap="20"
horizontalAlign="center" />
</s:layout>
<fx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
private var alert:Alert;
private function httpService_fault(evt:FaultEvent):void {
var title:String = evt.type + " (" + evt.fault.faultCode + ")";
var text:String = evt.fault.faultString;
alert = Alert.show(text, title);
Bezoekers.removeAll();
}
private function httpService_result(evt:ResultEvent):void {
var xmlList:XMLList = XML(evt.result).bezoekers.bezoeker;
Bezoekers = new XMLListCollection(xmlList);
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="httpService"
url="http://localhost/projectnieuw/src/data/bezoekersList.php"
resultFormat="e4x"
fault="httpService_fault(event);"
result="httpService_result(event)" />
<!--<fx:Model id="lijstAlleLeden" source="httpAlleLeden" />-->
<!--<s:ArrayCollection id="acBezoekers" source="{Bezoekers}"/>-->
<s:XMLListCollection id="Bezoekers"/>
</fx:Declarations>
<components:Heading/>
<s:HGroup gap="50">
<components:BezoekersList bezoekerList="{Bezoekers}" />
<components:ReservationForm/>
</s:HGroup>
</s:Application>
我没有收到任何错误,但我在列表中看不到任何信息。
答案 0 :(得分:3)
如果我明白你想做什么;那你就做不到。 Model标记是编译时值。实质上,该模型数据在编译时嵌入到我们的SWF中。而PHP脚本将在运行时执行。即使Flex会嵌入PHP文件;它将使用PHP代码,而不是执行PHP代码时得到的结果。
我建议在运行时从PHP脚本中查看loading the data。有很多方法可以做到这一点;取决于PHP脚本返回的内容。如果要使用HTTP Get Request加载它;我建议使用HTTPService。如果您可以使用AMF相关的东西,例如使用AMFPHP或ZenAMF,那么我会使用RemoteObject。