如何在 adobe flex 中显示 xml 文件中的产品列表
我有一个 html 文件,其中包含以下代码作为产品列表,
<productstore>
<product id='A1'>
<image lbl="Apple" src="assets/apple.png" />
<price>$11.00</price>
<description>Keeps doctor away</description>
<code>ap01</code>
</product>
</productstore>
我想在画布中显示带有名称和价格的图像(带有 flash builder 4.5 的 Flex)。我按照链接中给出的示例进行操作 http: //blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tilelist-control/
<mx:XML id="xml" source="prod.xml" />
<mx:XMLListCollection id="xmlListColl" source="{xml.image}" />
<mx:TileList id="tileList" x="492" y="10" width="255" height="316" columnCount="2"
columnWidth="125" dataProvider="{xmlListColl}"
itemRenderer="TileListItemRenderer" rowCount="4" rowHeight="100"
verticalScrollPolicy="on"/>
另外,我正在查看的修改是与示例不同,添加 DragAccept 而不是单击事件。
这是我的 TileListItemRenderer
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
x="492" y="10" width="255" height="316"
horizontalAlign="center"
verticalAlign="middle">
<mx:Image source="{data.@src}" />
<mx:Label text="{data.@lbl}" />
</mx:VBox>
当我构建并运行时列表为空,不确定我错过了什么。任何帮助将不胜感激。
我现在修改了代码,尝试实现以下链接,但再次卡住: http://blog. flexexamples.com/2008/03/29/dynamically-loading-xml-files-using-the-httpservice-tag/
main.mxml
private function init():void
{
var srcUrl:String = FlexGlobals.topLevelApplication.application.parameters.srcUrl;
if(srcUrl) {
ViewSource.addMenuItem(this, srcUrl);
}
loadProducts('prod.xml');
}
private function loadProducts(src:String):void {
httpService.url = src;
httpService.send();
}
private function httpService_result(evt:ResultEvent):void {
var xmlList:XMLList = XML(evt.result).product.image;
xmlListColl = new XMLListCollection(xmlList);
}
Itemrenderer
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
x="492" y="10" width="255" height="316" >
<mx:Image source="{data.image}" />
<mx:Label text="{data.name}" />
</mx:Canvas>
xml
<productlist>
<product>
<name>Apple</name>
<image>assets/apple.png</image>
<price>$11.00</price>
<description>Keeps doctor away</description>
<code>ap01</code>
</product>
</productstore>
仍然没有运气......
I have an html file with the following code as a list of products
<productstore>
<product id='A1'>
<image lbl="Apple" src="assets/apple.png" />
<price>$11.00</price>
<description>Keeps doctor away</description>
<code>ap01</code>
</product>
</productstore>
I want to display the image with the name and price in a canvas (Flex with flash builder 4.5).I followed the example given in the link
http://blog.flexexamples.com/2008/03/08/creating-a-simple-image-gallery-with-the-flex-tilelist-control/
<mx:XML id="xml" source="prod.xml" />
<mx:XMLListCollection id="xmlListColl" source="{xml.image}" />
<mx:TileList id="tileList" x="492" y="10" width="255" height="316" columnCount="2"
columnWidth="125" dataProvider="{xmlListColl}"
itemRenderer="TileListItemRenderer" rowCount="4" rowHeight="100"
verticalScrollPolicy="on"/>
Also the modification I am looking at is to add dragAccept rather than a click event unlike the example.
This is my TileListItemRenderer
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
x="492" y="10" width="255" height="316"
horizontalAlign="center"
verticalAlign="middle">
<mx:Image source="{data.@src}" />
<mx:Label text="{data.@lbl}" />
</mx:VBox>
When I build and run the list is empty, not sure what am I missing. Any help would be appreciated.
I now modified the code trying to implement the following link and again stuck:
http://blog.flexexamples.com/2008/03/29/dynamically-loading-xml-files-using-the-httpservice-tag/
main.mxml
private function init():void
{
var srcUrl:String = FlexGlobals.topLevelApplication.application.parameters.srcUrl;
if(srcUrl) {
ViewSource.addMenuItem(this, srcUrl);
}
loadProducts('prod.xml');
}
private function loadProducts(src:String):void {
httpService.url = src;
httpService.send();
}
private function httpService_result(evt:ResultEvent):void {
var xmlList:XMLList = XML(evt.result).product.image;
xmlListColl = new XMLListCollection(xmlList);
}
Itemrenderer
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
x="492" y="10" width="255" height="316" >
<mx:Image source="{data.image}" />
<mx:Label text="{data.name}" />
</mx:Canvas>
xml
<productlist>
<product>
<name>Apple</name>
<image>assets/apple.png</image>
<price>$11.00</price>
<description>Keeps doctor away</description>
<code>ap01</code>
</product>
</productstore>
Still no luck....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
{data}变量与xml节点相关。因此,如果您想引用 的“src”值,正确的绑定表达式应该是:
尝试这个并让我们知道结果。
The {data} variable is related to the xml node. So, if you want to reference the 's "src" value, the correct binding expression should be:
Try this and let us know about the results.