【问题标题】:Flex - Data binding not workingFlex - 数据绑定不起作用
【发布时间】:2011-02-15 06:15:31
【问题描述】:

我在绑定数据时遇到了一些问题。

我有一个包含组件视图堆栈的应用程序。 假设我在视图堆栈中有 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>

SearchResult 和 Reporting 都访问 Order。

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 中,我有一个 hbox 列表,其结构与前两个 Hbox 中所示的结构相同。

关于数据源,这些是我正在使用的以下数据源,它们的预期行为和实际行为:

@

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

【问题讨论】:

  • 你能发布一些代码吗?很难理解您的代码实际在做什么。
  • 除非您发布代码,否则任何帮助都将是奇迹。

标签: apache-flex data-binding


【解决方案1】:

看起来没人发现代码有什么问题?? 我也不。但是对代码进行其他修改,它终于奏效了。还是不知道为什么……>_

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 2016-01-16
    • 2018-10-27
    • 2018-12-27
    • 2018-12-09
    • 1970-01-01
    相关资源
    最近更新 更多