2009-11-02 44 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或者只是發送一次性值(即:發送常量時),則可以忽略該消息。