如何将 E4X 属性解释为 Flex 中的日期?

发布于 2024-07-27 19:01:32 字数 252 浏览 10 评论 0原文

我有如下所示的 XML:

<item>
     <itemDate>07/10/2009</itemDate>
</item>

我希望能够将其作为 E4X 对象读取:item.itemDate 并使 itemDate 成为 ActionScript Date 对象而不是字符串。 这可能吗?

I've got XML that looks like this:

<item>
     <itemDate>07/10/2009</itemDate>
</item>

I would like to be able to read this in as an E4X object: item.itemDate and have itemDate be an ActionScript Date object instead of a string. Is this possible?

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

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

发布评论

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

评论(2

人海汹涌 2024-08-03 19:01:33

如果我理解正确的话,不。 以 XML 形式出现的所有内容都将是一个字符串 - 甚至是其他原语,如“1”或“false”。

当我必须处理类似的事情时,我会迭代 XML 并创建一个镜像对象(有时甚至是一个无类型对象),并将 String 值转换为其适当的数据类型。

或者,我只是在使用之前将值转换为其适当的数据类型。

If I understand you right, Nope. Everything that comes in as XML will be a string - even other primitives like "1", or "false".

When I have to deal with something like this, I iterate through the XML and create a mirroring Object (sometimes an untyped Object, even) and convert the String values to their appropriate datatypes.

Or, I just convert the value to its appropriate datatype just before use.

意中人 2024-08-03 19:01:33

只需将值传递给 日期构造函数

for each(var itemNode:XML in doc.item)
{
    var itemDate : Date = new Date(itemNode.itemDate);
}

Just pass the value to the Date constructor:

for each(var itemNode:XML in doc.item)
{
    var itemDate : Date = new Date(itemNode.itemDate);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文