2009-11-02 73 views
0

我有一个PresentationModel AS类,其中包含SomeView.mxml中使用的所有值。模型的整个类都是可绑定的,并且视图中的模型属性也是可绑定的。然而,我无法使用PropertyInjector标签注入模型到视图:注入由OjbectBuilder创建的对象作为属性来查看

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

会有人与熟悉并且灵活数据绑定和队友给我个忙吗?非常感谢!

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> 
+0

PresentationModel的其余部分是什么样的? – Stiggler 2009-11-10 18:07:46

回答

0

您不能绑定到一个类。制作可绑定类意味着该类的所有成员都是可绑定的,但不是定义本身。

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

1

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

当你有一个带有source和source键的PropetyInjector时,通常会显示这条消息,其中由“sourceKey”定义的属性不可绑定,所以我们要确保你知道该属性的当前值是只有一个目标会得到(当属性不可绑定时,该值被复制并且不建立绑定)。这可能是也可能不是你想要的。

在这种情况下,没有sourceKey,因为您不想绑定到源的任何特定属性。相反,你想将整个PM传递给视图。因此,您不想建立绑定,只需将值发送到视图一次。

如果没有sourceKey或者只是发送一次性值(即:发送常量时),则可以忽略该消息。