帮助理解 Flex 中值对象的用法

发布于 2024-08-16 18:10:31 字数 683 浏览 4 评论 0原文

我在理解 Flex 中的值对象时遇到一些小问题...我试图从 PHP/MySQL 获取一些数据并将其发送到 Flex,但我陷入了一些(显然)基本问题...

让我们说我的Flex 中的对象看起来像这样:

package some.package.VO {

    [RemoteClass(alias="VOPerson")]

    [Bindable]
    public class VOPerson {
        public var personID:int;
        public var firstName:String;
        public var lastName:String;
        public var personDetails:Array;
    }
}

在我的例子中,personDetails 是一个数组,理论上,它可能是其他一些对象......但是真的有必要将其设为一个对象吗? ?除了我的 VOPerson 类之外,我不打算在其他地方使用该数据。它是一些关联数组,我可以轻松地将它转换为另一个对象,但是我的应用程序中会有很多类似的情况,所以如果不需要它,我想避免创建不必要的(值)对象......

不管怎样,任何关于我的问题的提示/提示/链接将不胜感激! :)
非常感谢!

I have some small problem in understanding Value Objects in Flex... I'm trying to get some data from PHP/MySQL and send it to Flex but I'm stuck in some (obviously) basic problems...

Let's say That my object in Flex would look like this:

package some.package.VO {

    [RemoteClass(alias="VOPerson")]

    [Bindable]
    public class VOPerson {
        public var personID:int;
        public var firstName:String;
        public var lastName:String;
        public var personDetails:Array;
    }
}

In my case, personDetails is an Array, and in theory, it could be some other object... But is it really necessary to make it an object? I do not intend to use that data nowhere else except within my VOPerson class. It is some associative array, and I can easily transform it to another object, but there will be lots of similar situations in my app, so I would like to avoid making unnecessary (value) objects if there is no need for it...

Anyway, any tip/hint/link about my problem would be really appreciated! :)
Thank you very much!

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

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

发布评论

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

评论(1

黑寡妇 2024-08-23 18:10:31

我不像 Java/Flex 那样熟悉 PHP/Flex 序列化,但我相信同样的原则也适用。如果 personDetails 是一个基元数组,Flex 将对其进行序列化。如果 personDetails 是 Fl​​ex 不知道如何序列化的类型(即您没有将其定义为 RemoteClass),它将被转换为匿名对象。

如果您一开始就试图阻止 PHP 代码中的 personDetails 被序列化为 Flex,那么这可能会更加棘手。我知道 Flex 通过查找公共 getter/setter 对来识别 Java 中的可序列化字段,因此您可以通过简单地不公开 getter 和 setter 来防止序列化。您可能可以在 PHP 中执行一些类似的技巧。

I'm not as familiar with PHP/Flex serialization as I am with Java/Flex, but I believe the same principles will hold. If personDetails is an array of primitives, it will be serialized as such by Flex. If personDetails is a type that Flex does not know how to serialize (i.e. you haven't defined it as a RemoteClass), it will be converted to an anonymous object.

If you're trying to prevent personDetails in your PHP code from being serialized to Flex in the first place, that might be more tricky. I know that Flex identifies serializable fields in Java by looking for a public getter/setter pair, so you can prevent serialization by simply not exposing a getter and setter. There might be some similar trick you can do in PHP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文