1

我正在使用 Flash Builder 4,并且我有一个名为 words.xml 的外部 XML 文件,其结构如下:

<wordList>
    <wordRecord>
        <word>duck</word>
        <syllables>1</syllables>
        <firstLetter>d</firstLetter>
        <!--other fields-->
    </wordRecord>
    <wordRecord>
        <word>machete</word>
        <syllables>3</syllables>
        <firstLetter>m</firstLetter>
        <!--other fields-->
    </wordRecord>
    <!--more wordRecords-->
</wordList>

现在,请注意,这些不是确切的字段名称或内容,因为它们是我的客户专有的,这是我的客户的 XML 文件。但这是基本结构。我只需要显示列表中每个“wordRecord”中的“word”字段,这将通过拖放和其他好东西来启用。

Flash Builder MXML 文件的相关部分是:

<fx:Declarations>
    <fx:XML id="wordsXML" source="/xml/words.xml" />
<fx:Declarations>
<s:List id="resultsList">
    <s:dataProvider>
        <s:XMLListCollection id="xmlWords" source="{wordsXML..word}" />
    </s:dataProvider>
</s:List>

到目前为止,一切都很好。列表在我的 Air 应用程序、滚动条和所有内容中显示得很好,当存在适当的属性时,拖放效果很好。

但是,我需要的是能够根据其他字段过滤列表,并仅显示结果中的单词。

出于目前的目的,让我们假设 XML 文件包含很多很多“wordRecord”元素,我需要创建一个 filterFunction 最终将只给我“firstLetter”是的“单词”,假设“m”。

我尝试根据我在网上找到的一些示例创建一个 filterFunction,但由于我的 XMLListCollection 只是字段,我无法让 filterFunction 与其他 XML 字段一起使用。我尝试更改 XMLListDeclaration 以将每个“wordRecord”元素作为 XMLList 给我,但后来我无法弄清楚如何让 s:List 仅显示来自 filterFunction 的结果的“word”。

有任何想法吗?提前致谢。

4

1 回答 1

1
<s:List id="resultsList" labelField="word">
    <s:dataProvider>
        <s:XMLListCollection
                id="xmlWords"
                source="{wordsXML..wordRecord}"
                />
    </s:dataProvider>
</s:List> 

这样,您的过滤器功能就有了“wordRecord”对象;

于 2012-04-19T06:46:39.273 回答