E4X 条件调用仅返回 1 个匹配项而不返回任何内容?

发布于 2024-07-14 14:53:01 字数 993 浏览 11 评论 0原文

好的,这是我的代码:

var xml:XML = 
<xml>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-17"/>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-16"/>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-17"/>
    <typeB amount1="500" amount2="300" amount3="250" date="2008-02-18"/>
    <typeB amount1="500" amount2="300" amount3="250" date="2008-02-19"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-20"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-21"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-20"/>
</xml>;


trace(xml.typeA.(@date == "2008-02-16")); // no results
trace(xml.typeA.(@date == "2008-02-17")); // finds both
trace(xml.typeC.(@date == "2008-02-20")); // finds both
trace(xml.typeC.(@date == "2008-02-21")); // no results

似乎只有在出现次数超过 1 次时才能找到它。

难道我做错了什么?

ok here is my code:

var xml:XML = 
<xml>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-17"/>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-16"/>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-17"/>
    <typeB amount1="500" amount2="300" amount3="250" date="2008-02-18"/>
    <typeB amount1="500" amount2="300" amount3="250" date="2008-02-19"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-20"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-21"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-20"/>
</xml>;


trace(xml.typeA.(@date == "2008-02-16")); // no results
trace(xml.typeA.(@date == "2008-02-17")); // finds both
trace(xml.typeC.(@date == "2008-02-20")); // finds both
trace(xml.typeC.(@date == "2008-02-21")); // no results

It seems like it is only finding it if there is more then 1 occurance.

Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

病毒体 2024-07-21 14:53:01

实际上它找到了它,但因为它只是一项,所以它以 XML(而不是 XMList)的形式跟踪它。
节点为空时,它只会跟踪一个空字符串。

试试这个:

<typeA amount1="500" amount2="300" amount3="250" date="2008-02-16">Hello</typeA>

当您调试 XML 时,您最好使用 toXMLString 方法。

trace(xml.*.(@date="1980-04-29").toXMLString());

Actually it finds it but because it's only one item it traces it as an XML (instead of XMList).
The node being empty it will just trace an empty string.

Try this :

<typeA amount1="500" amount2="300" amount3="250" date="2008-02-16">Hello</typeA>

When you are debugging XML you'd better use the toXMLString method.

trace(xml.*.(@date="1980-04-29").toXMLString());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文