注入 OjbectBuilder 创建的对象作为属性来查看

发布于 2024-08-10 14:34:38 字数 1423 浏览 5 评论 0原文

我有一个 PresentationModel AS 类,它保存 SomeView.mxml 中使用的所有值。模型的整个类都是可绑定的,视图中的模型属性也是可绑定的。但是,我无法使用 PropertyInjector 标签将模型注入到视图中:

- INFO: Data binding will not be able to detect assignments to model

熟悉 Flex 数据绑定和 Mate 的人可以帮我吗?多谢!

MainEventMap.mxml

<EventHandlers type="{FlexEvent.INITIALIZE}">
    <ObjectBuilder generator="{PresentationModel}" registerTarget="true">
        <Properties dispatcher="{scope.dispatcher}"/>
    </ObjectBuilder>
</EventHandlers>


<Injectors target="{SomeView}" debug="true">
    <PropertyInjector targetKey="model" source="{PresentationModel}" />
</Injectors> 

来自 PresentationModel.as 的片段

[Bindable]
public class PresentationModel extends EventDispatcher
{
    public var dispatcher:IEventDispatcher;

    //.....other variables and functions
}

来自 SomeView.mxml 的片段

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="518" height="562" >
<mx:Script>
    <![CDATA[

         //...... all the imports

        [Bindable]
        public var model:OSGiBrokerConsoleModel;

        // ......other variables and functions
    ]]>
</mx:Script>

    // ..... actual view components

</mx:Canvas>

I have a PresentationModel AS class that holds all the values used in SomeView.mxml. The entire class for the model is bindable, and the model property in the view is also bindable. However, I am unable to inject the model into the view using the PropertyInjector tag:

- INFO: Data binding will not be able to detect assignments to model

Would someone familier with Flex data binding and Mate give me a hand? Thanks a lot!

MainEventMap.mxml

<EventHandlers type="{FlexEvent.INITIALIZE}">
    <ObjectBuilder generator="{PresentationModel}" registerTarget="true">
        <Properties dispatcher="{scope.dispatcher}"/>
    </ObjectBuilder>
</EventHandlers>


<Injectors target="{SomeView}" debug="true">
    <PropertyInjector targetKey="model" source="{PresentationModel}" />
</Injectors> 

Snippet from PresentationModel.as

[Bindable]
public class PresentationModel extends EventDispatcher
{
    public var dispatcher:IEventDispatcher;

    //.....other variables and functions
}

Snippet from SomeView.mxml

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="518" height="562" >
<mx:Script>
    <![CDATA[

         //...... all the imports

        [Bindable]
        public var model:OSGiBrokerConsoleModel;

        // ......other variables and functions
    ]]>
</mx:Script>

    // ..... actual view components

</mx:Canvas>

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

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

发布评论

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

评论(2

阿楠 2024-08-17 14:34:38

您可以安全地忽略该信息消息。

当您有一个带有源和源键的 PropetyInjector 时,通常会显示该消息,其中“sourceKey”定义的属性不可绑定,因此我们希望确保您知道该属性的当前值将是唯一的目标值将永远获得(当属性不可绑定时,将复制该值并且不建立绑定)。这可能是也可能不是您想要的。

在本例中,没有 sourceKey,因为您不想绑定到源的任何特定属性。相反,您希望将整个 PM 传递给视图。因此,您不想建立绑定,只需将值发送到视图一次即可。

在没有 sourceKey 的情况下或者当您只是发送一次性值时(即:当您发送常量时),可以忽略该消息。

You can safely ignore that information message.

That message is usually shown when you have a PropetyInjector with source and source key, where the property defined by "sourceKey" is not bindable, so we want to make sure you know that the current value of that property will be the only one the target will ever get (when the property is not bindable, the value is copied and no binding is established). That may or may not be what you want.

In this case, there is no sourceKey, because you don't want to bind to any specific property of the source. Instead, you want to pass the whole PM to the view. Because of that, you don't want to establish a binding, just send the value to the view once.

In the cases where there is no sourceKey or when you are simply sending a one-off value (ie: when you are sending a constant), the message can be ignored.

梦断已成空 2024-08-17 14:34:38

您无法绑定到类。使类可绑定意味着该类的所有成员都将可绑定,但定义本身除外。

您应该为表示模型创建一个成员函数(getter/setter),该函数返回要用作源的数据。然后,您还需要创建可用于绑定的PresentationModel 实例。因此,您不需要绑定到PresentationModel.data,而是绑定到myPM.data。

You cannot bind to a class. Making a class bindable means all members of that class will be bindable, but not the definition itself.

You should create a member function(getter/setter) for the presentation model that returns the data you want to use as the source. Then you also need to create an instance of PresentationModel that you can use for the binding. So rather than binding to PresentationModel.data, you'd bind to myPM.data.

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