Flex Hero:加载 XML 数据有效,但列表未更新
我有这个 Flex 4.5 (Burrito) Mobile 项目:
它由 2 个文件组成 - TextXML.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:MobileApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:components="spark.components.*"
firstView="views.Home">
</s:MobileApplication>
和Home.mxml 带有 1 个按钮、1 个列表和 1 个 HTTPService:
<?xml version="1.0" encoding="utf-8"?>
<s:View
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:components="spark.components.*"
title="Home">
<fx:Script>
<![CDATA[
import mx.collections.*;
import mx.events.*;
import mx.rpc.events.*;
import mx.utils.*;
import spark.events.*;
[Bindable]
public var myColl:XMLListCollection = new XMLListCollection();
public function srvResult(event:ResultEvent):void {
trace(ObjectUtil.toString(event.result));
myColl.source = event.result.pref.user.money;
myList.dataProvider = myColl;
}
public static function myLabelFunc(item:Object):String {
return item.yw;
}
public static function myMessageFunc(item:Object):String {
return item.max;
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService
id="httpSrv"
url="http://preferans.de/user-xml.php?id=OK123195454365"
resultFormat="e4x"
result="srvResult(event)"
fault="trace(event.fault.message)" />
</fx:Declarations>
<s:navigationContent>
<s:Button label="Load XML" click="httpSrv.send()"/>
</s:navigationContent>
<s:List id="myList"
top="0" bottom="0" left="0" right="0"
dataProvider="{myColl}">
<s:itemRenderer>
<fx:Component>
<s:MobileIconItemRenderer
labelFunction="Home.myLabelFunc"
messageFunction="Home.myMessageFunc" >
</s:MobileIconItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:View>
当我在调试器中运行我的应用程序(以便我可以在控制台中看到跟踪输出)并单击“加载 XML”按钮时,我看到 XML 数据是从我的PHP脚本加载正常:
<pref>
<user id="OK123195454365" first_name="Dmitry"
city="Moscow" money="8815" medals="1">
<money yw="2011-01" max="8815" user="8815"/>
<money yw="2010-52" max="6380" user="1545"/>
<money yw="2010-51" max="8797" user="2094"/>
<money yw="2010-50" max="8446" user="2080"/>
</user>
</pref>
但不幸的是列表仍然是空的。
我有一种感觉,这里缺少一件小事,也许应该将一个事件发送到列表?我已经尝试重新分配其 dataProvider,如您在上面看到的,但这对我没有帮助......
谢谢!亚历克斯
I have this Flex 4.5 (Burrito) Mobile project:
It consists of 2 files - the TextXML.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:MobileApplication
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:components="spark.components.*"
firstView="views.Home">
</s:MobileApplication>
and the Home.mxml with 1 Button, 1 List and 1 HTTPService:
<?xml version="1.0" encoding="utf-8"?>
<s:View
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:components="spark.components.*"
title="Home">
<fx:Script>
<![CDATA[
import mx.collections.*;
import mx.events.*;
import mx.rpc.events.*;
import mx.utils.*;
import spark.events.*;
[Bindable]
public var myColl:XMLListCollection = new XMLListCollection();
public function srvResult(event:ResultEvent):void {
trace(ObjectUtil.toString(event.result));
myColl.source = event.result.pref.user.money;
myList.dataProvider = myColl;
}
public static function myLabelFunc(item:Object):String {
return item.yw;
}
public static function myMessageFunc(item:Object):String {
return item.max;
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService
id="httpSrv"
url="http://preferans.de/user-xml.php?id=OK123195454365"
resultFormat="e4x"
result="srvResult(event)"
fault="trace(event.fault.message)" />
</fx:Declarations>
<s:navigationContent>
<s:Button label="Load XML" click="httpSrv.send()"/>
</s:navigationContent>
<s:List id="myList"
top="0" bottom="0" left="0" right="0"
dataProvider="{myColl}">
<s:itemRenderer>
<fx:Component>
<s:MobileIconItemRenderer
labelFunction="Home.myLabelFunc"
messageFunction="Home.myMessageFunc" >
</s:MobileIconItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:View>
When I run my app in the debugger (so that I can see the trace output in the console) and click the "Load XML" button, then I see that XML data is loading ok from my PHP script:
<pref>
<user id="OK123195454365" first_name="Dmitry"
city="Moscow" money="8815" medals="1">
<money yw="2011-01" max="8815" user="8815"/>
<money yw="2010-52" max="6380" user="1545"/>
<money yw="2010-51" max="8797" user="2094"/>
<money yw="2010-50" max="8446" user="2080"/>
</user>
</pref>
But the List unfortunately stays empty.
I have a feeling that a minor thing is missing here, maybe an event should be sent to the List? I've tried reassigning its dataProvider as you can see above, but it doesn't help me...
Thank you! Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的代码中有几个问题:
以下代码应该有效:
There are several issues in your code :
The following code should work :
当只有 1 个子节点时,由于某种原因 Flex 不再将其视为数组,因此您必须直接引用该节点。
When there is only 1 child node, for some reason Flex no longer treats it as an array, so you have to reference the node directly.
你有没有尝试过:
Have you try: