如何在adobe flex中的xml文件中显示产品列表

时间:2011-11-07 20:01:45

标签: xml flex4 adobe

我有一个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>

我想在画布中显示名称和价格的图像(Flex with flash builder 4.5)。我按照链接中给出的示例进行操作 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>

仍然没有运气......

1 个答案:

答案 0 :(得分:0)

{data}变量与xml节点相关。因此,如果要引用's“src”值,则正确的绑定表达式应为:

{data.image.@src}

试试这个并告诉我们结果。