代码之家  ›  专栏  ›  技术社区  ›  SubSevn

用XML提要中的内容填充flex中的datagrid

  •  0
  • SubSevn  · 技术社区  · 16 年前

    我有一个数据网格:

        <mx:DataGrid id="resultsDataGrid" 
                     height="328" width="604" paddingRight="0" editable="false" y="43" horizontalCenter="0">
            <mx:columns>
                <mx:DataGridColumn headerText="Title" dataField="title"/>
                <mx:DataGridColumn headerText="Updated" dataField="updated"/>
            </mx:columns>
        </mx:DataGrid>
    

    <feed xmlns="http://www.w3.org/2005/Atom">
    <title></title>
    <link href=""/>
    <link rel="" href=""/>
    <updated></updated>
    <author>
        <name></name>
    </author>
    <id></id>
    <entry>
    <title></title>
    <link href=""/>
    <id></id>
    <updated></updated>
    <published></published>
    <summary></summary>
    <author>
        <name></name>
    </author>
    <category term="" label=""/>
    <category term="" scheme=""/>
    </entry>
    </feed>
    

    现在,所有这些字段在返回时都会被填充,但为了更简单,我删除了这些值。

            private function searched(event:ResultEvent):void
            {
                var result:XML = XML(event.result);
                //summaryText.text = result.toXMLString();
                //Alert.show(result.children().children().children().toString() + "hey");
                resultsDataGrid.dataProvider = result.entry;
            }
    

    我只需要将标题和更新的字段实际加载到DataGrid中。 这显然不起作用,所以我来寻求帮助,如果有人有经验,可以告诉我如何正确安排,我将不胜感激。(我认为这与结果输入,一定是别的什么东西result.feed.entry输入,但我尝试了许多组合,但都没有成功——除非我没有找到正确的组合。)

    1 回复  |  直到 16 年前
        1
  •  2
  •   jooks    16 年前

    最简单的解决方案:不要使用名称空间。

    否则:您需要在此处进行一些研究: http://livedocs.adobe.com/flex/3/langref/Namespace.html

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:XML id="atomNamespace">
            <feed xmlns="http://www.w3.org/2005/Atom">
                <title></title>
                <link href="" />
                <link rel="" href="" />
                <updated></updated>
                <author>
                    <name></name>
                </author>
                <id></id>
                <entry>
                    <title>Title text</title>
                    <link href="" />
                    <id></id>
                    <updated>2010-09-10</updated>
                    <published></published>
                    <summary></summary>
                    <author>
                        <name></name>
                    </author>
                    <category term="" label="" />
                    <category term="" scheme="" />
                </entry>
            </feed>
        </mx:XML>
        <mx:XML id="noNamespace">
            <feed>
                <title></title>
                <link href="" />
                <link rel="" href="" />
                <updated></updated>
                <author>
                    <name></name>
                </author>
                <id></id>
                <entry>
                    <title>Title text</title>
                    <link href="" />
                    <id></id>
                    <updated>2010-09-10</updated>
                    <published></published>
                    <summary></summary>
                    <author>
                        <name></name>
                    </author>
                    <category term="" label="" />
                    <category term="" scheme="" />
                </entry>
            </feed>
        </mx:XML>
        <mx:DataGrid id="resultList">
            <mx:columns>
                <mx:DataGridColumn headerText="Title" dataField="title" />
                <mx:DataGridColumn headerText="Updated" dataField="updated" />
            </mx:columns>
        </mx:DataGrid>
        <mx:Button label="Atom Namespace" click="resultList.dataProvider = atomNamespace..entry"/>
        <mx:Button label="No Namespace" click="resultList.dataProvider = noNamespace..entry"/>
    </mx:Application>
    
    推荐文章