2010-05-03 88 views
0

我在綁定數據時遇到了一些麻煩。Flex - 數據綁定不起作用

我有一個包含組件視圖的應用程序。 假設我在viewstack中有comp1,comp2和comp3。 每個組件都有其自己的數據類 - > comp1Data.as,comp2Data.as和comp3Data.as。 每個組件中的所有值都綁定到其數據對象中的相應數據。

單擊comp1中的控件導致comp3,comp2也是如此。點擊comp2中的控件導致comp3。 從comp1到comp3時,comp3Data.as被初始化,而comp3顯示綁定的值。 當從comp2到comp3,comp3Data.as也初始化,但綁定值不顯示...

我試過使用初始化,但它不工作。在調試時,數據就在那裏,但不顯示。

任何幫助將非常感激。 問候,

BS_C3


一些代碼^ __^ 主要應用:

<mx:Application> 
    <mx:Script> 
     <![CDATA[ 
      private function order(s:String):void 
      { 
       if(s == 'order') 
        OrderData.instance.state = 'order'; 
       else if(s == 'reporting') 
       { 
        OrderData.instance.state = 'reporting'; 
        . 
        . 
        . 

       } 
       pages.selectedChild = or; 
      } 
     ]]> 
    </mx:Script> 

    <mx:ViewStack id="pages" horizontalCenter="0" verticalCenter="0" width="100%" height="100%"> 
     <components:SearchResult id="sr" width="100%" 
      order="order('order')" 
      /> 
     <components:Reporting id="rp" width="100%" 
      reportingOrder="order('reporting')"/> 
     <components:Order id="or" width="100%" 
      /> 
    </mx:ViewStack> 
</mx:Application> 

兩個信息搜索結果和報告存取權限秩序。

Order.mxml看起來是這樣的:

<mx:Canvas> 
    <mx:HBox width="100%"> 
     <mx:Box paddingBottom="15" paddingLeft="15" paddingRight="15" paddingTop="15" backgroundColor="#FFFFFF" height="100%"> 
      <components:OrderView id="ov"/> 
     </mx:Box> 
     <mx:Spacer width="15"/> 
     <components:OrderedSDR id="sdr" height="100%"/>  
    </mx:HBox> 
</mx:Canvas> 

我越來越煩惱與OrderedSDR.mxml:

<mx:Canvas> 
    <mx:VBox width="100%" height="100%" paddingBottom="28" paddingLeft="28" paddingRight="28" paddingTop="28" backgroundColor="#FFFFFF"> 
     <mx:HBox width="100%" paddingBottom="6" horizontalAlign="center"> 
      <mx:Canvas> 
       <mx:Image id="thumbnailBG" source="@Embed(source='assets/Images/SearchResult/BoxBagueOverview.PNG')"/>    
       <mx:Image id="overview" source="{GlobalData.instance.collection.overview.toString()}"/> 
       <mx:Label id="thumbnailCarats" 
        text="{GlobalData.instance.collection.carats.toString() + GlobalData.instance.languageProperties.orderedSDR.imageInfo.toString()}" 
        styleName="OVLBL" 
        paddingBottom="5" paddingRight="10" 
        x="{thumbnailBG.x + thumbnailBG.width - thumbnailCarats.width}" 
        y="{thumbnailBG.y + thumbnailBG.height - thumbnailCarats.height}"/> 
      </mx:Canvas> 
     </mx:HBox> 
     <mx:VBox id="mainBox" paddingBottom="8" paddingTop="8" verticalGap="6" width="180"> 
      <mx:HBox width="100%" height="13"> 
       <mx:Label width="80" 
        text="{GlobalData.instance.languageProperties.orderedSDR.product.toString()}" 
        styleName="OVDataLbl" opaqueBackground="#ECE5E2"/> 
       <mx:Label text="{SearchResultData.instance.selectedSDR.matnr_fp}" styleName="OVData"/> 
      </mx:HBox> 

     <mx:HBox width="100%" height="13"> 
      <mx:Label width="80" 
       text="{GlobalData.instance.languageProperties.orderedSDR.netPrice.toString()}" 
       styleName="OVDataLbl" opaqueBackground="#ECE5E2"/> 
      <mx:Label text="{SearchResultData.instance.selectedSDR.currSymbol + ' ' + SearchResultData.instance.selectedSDR.fNet_price_fp}" styleName="OVData"/> 
     </mx:HBox> 

      . 
      . 
      . 
     </mx:VBox> 
    </mx:VBox> 
</mx:Canvas> 

裏面mainBox,我有橫向盒的列表具有相同的結構如前兩個Hboxes所示。

關於數據源,這些都是下面的數據源,我使用,他們的預期行爲和實際行爲:

@

Embed(source='assets/Images/SearchResult/BoxBagueOverview.PNG --> The image is displayed as it should 

GlobalData.instance.collection.overview.toString() --> GlobalData.instance.collection is a XMLList that contains the data for the image with id="overview". I do get the correct source, but the image is not displayed. 

GlobalData.instance.languageProperties. ... --> It's a XMLList. The data is shown as it should. 

SearchResultData.instance.selectedSDR.matnr_fp --> SearchResultData.instance.selectedSDR is an object that contains all the data that has to be displayed. Matnr_fp is a property of this object. And each hbox inside mainbox have to display a property of the object selectedSDR. The only property that is being displayed is SearchResultData.instance.selectedSDR.currSymbol. The other properties are not displaying even if the datasource is populated. 

希望這將是有益的。 謝謝!

問候, BS_C3

+2

你能發表一些代碼嗎?很難跟蹤你的代碼實際在做什麼。 – bedwyr 2010-05-04 00:12:06

+0

除非您發佈您的代碼,否則任何幫助都將是不可思議的。 – Robusto 2010-05-04 00:23:04

回答

0

貌似沒有人看到什麼不對的代碼? 我也沒有。但是對代碼做了其他修改,它終於奏效了。仍然不知道爲什麼...> _ <