【问题标题】:Alternative method for creationcomplete创建完成的替代方法
【发布时间】:2010-07-04 20:30:34
【问题描述】:

我正在尝试将一堆产品详细信息从 List 组件加载到画布组件中。

每次用户点击我的列表中的产品时,产品详细信息都会显示在画布组件中。产品详细信息可能包含 null,我想在我的画布组件中显示之前对其进行检查。

在我的画布组件中,我使用 createcomplete 检查 productDetail==null 是否然后执行某些操作。我的问题是,如果用户第一次单击具有非空详细信息的产品,如果用户单击空产品详细信息,则语句“if (productDetail==null) then do something”将不起作用,因为画布组件已在用户第一次单击非空产品详细信息时创建。

我想在每次用户点击产品时检查 productDetail==null...我希望我能很好地解释我的问题并感谢任何帮助。

我的代码..

作为:

protected function changeHandler(event:IndexChangeEvent):void{

   compDetailinfoResult.token=getCompList.compDetail(event.target.selectedItem.productId);//get the product detail clicked by the user

}


<s:List dataProvider={productData}/>  //when user click a product, 
                                      //the canvas will show product detail..

<comp:productDetail productData={compDetailinfoResult.lastResult} //custom property 
                    change="changeHandler"/>  //if the product detail is 
                 //null, the statement inside 
                 //the canvas will check via 
                 //creationComplete. but if the 
                 //user click the non-null product, 
                 //the creationComplete check pass. User clicks a null product again,  
                 //the check won't work anymore...

我的 productDetail 组件的代码:

public var productData:arrayCollection

protected function canvas1_creationCompleteHandler(event:FlexEvent):void
{
var undefinedBrand:String=dataFromClick.getItemAt(0).brand;

    if(undefinedBrand==null){   // I want to check every time the user click a List item
      brand.text="Brand: No Brand";
      switchView.enabled=false;
      displayPictureBig.source="assets/vacant.jpg";
     }
}

    <s:Panel>
       <label id="brand" text="productDate.getItemAt(0).brand"/> 
//I want the brand to be displayed..
//but if brand is null..it will display No Brand..
//see AC above...but createComplete only fire once.
//Anyway to keep tracking if the brand that is sent by List is null?
    </s:Panel

感谢您的帮助..

【问题讨论】:

    标签: apache-flex


    【解决方案1】:

    我无法理解您的问题。您是否明确提到了 Halo 容器 Canvas?或者您是否将您的自定义组件之一命名为 Canvas?如果它是自定义的,如您的代码所示,组件内部是什么?

    creationComplete 是一个仅在组件第一次完成运行组件生命周期创建过程时触发一次的事件。您的代码 sn-ps 没有显示任何从列表传递到画布的数据,因此这可能是数据为空的原因之一。

    如果有人在列表中选择了一个新项目,change 事件应该发送。您可以向 change 事件添加事件侦听器,并使用它来更新您发送到画布组件中的数据。

    【讨论】:

    • 很抱歉给您带来了困惑。我在这里只粘贴非常基本的代码。请查看更新的代码...
    • 我确实有主应用程序发送的数据。 productDetail 组件接收数据并显示它。产品详细信息将根据用户在列表中单击的产品而改变。某些产品品牌为空,我想在用户单击无品牌产品时显示无品牌...感谢您的帮助...:D
    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 2014-12-22
    • 2013-04-05
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多