简体   繁体   English

如何在Adobe Flex中显示xml文件中的产品列表

[英]how to display products list from an xml file in adobe flex

I have an html file with the following code as a list of products 我有一个带有以下代码的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>

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/ 我想在画布上显示带有名称和价格的图像(带有Flash Builder 4.5的Flex)。我按照链接http://blog.flexexamples.com/2008/03/08/creating-a-中给出的示例进行操作带有灵活瓷砖列表控件的简单图片库/

<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. 另外,我正在查看的修改是添加dragAccept而不是与示例不同的click事件。

This is my TileListItemRenderer 这是我的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/ 我现在修改了代码,尝试实现以下链接,并再次卡住: http : //blog.flexexamples.com/2008/03/29/dynamically-loading-xml-files-using-the-httpservice-tag/

main.mxml 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 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.... 还是没有运气。

The {data} variable is related to the xml node. {data}变量与xml节点相关。 So, if you want to reference the 's "src" value, the correct binding expression should be: 因此,如果要引用的“ src”值,则正确的绑定表达式应为:

{data.image.@src}

Try this and let us know about the results. 试试这个,让我们知道结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM