E4X 中字符串的通配符?
我正在尝试使用 E4X 解决 Actionscript 问题。 我有一个像这样的 XML:
<root>
<person firstname="john" lastname="doe" age="21" />
<person firstname="jayne" lastname="doe" age="35" />
<person firstname="john" lastname="miller" age="42" />
</root>
我只想有一个函数 search(),它接受三个参数(名字、姓氏、年龄)并返回一个 XMLList。所以结果可能如下所示:
var result:XMLList = xml..person.(@firstname == firstName && @lastname == lastName && @age == age );
但我不想一直使用所有三个参数。我想要一个在参数为 NULL 时使用“通配符”的函数。因此,如果通配符为“*”,则该函数可能如下所示:
searchPerson( firstName:String ="*", lastName:String = "*" , age:String = "*") {...}
这样我就只为firstName 传递“John”,我将得到第一个和第三个节点作为回报。
怎么做呢?
I'm trying to solve an Actionscript problem using E4X.
I have an XML like this one:
<root>
<person firstname="john" lastname="doe" age="21" />
<person firstname="jayne" lastname="doe" age="35" />
<person firstname="john" lastname="miller" age="42" />
</root>
I want to have just one function search() that takes three parameters (firstname, lastname, age) and return an XMLList. So the result could look like this:
var result:XMLList = xml..person.(@firstname == firstName && @lastname == lastName && @age == age );
But I don't want to use all three parameters all the time. I would like to have a function that uses a 'wilcard' if the parameter is NULL. So if the wildcard would be "*" the function could look like:
searchPerson( firstName:String ="*", lastName:String = "*" , age:String = "*") {...}
so that I would only pass 'John' for the firstName I'd get the first and the third node in return.
How to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
attribute("your-attribute")
的布尔值将指示特定属性是否存在。The boolean value of
attribute("your-attribute")
will indicate if a particular attribute is present.好的。我可以检查所有属性。但我会留下 7 个不同的选项:
我更喜欢一句俏皮话,这就是为什么我正在寻找像通配符这样的东西。
Ok. I could check all attributes. But I would be left with 7 different options:
I'd prefer a one-liner, that's why I'm looking for something like a wildcard.