2010-07-04 100 views
0

我想从一个列表组件中加载一堆产品详细信息到一个画布组件。替代方法creationcomplete

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

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

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

我的代码..

AS:我的产品详情成分

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... 

代码:

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 

感谢您的帮助..

回答

1

我遇到了一些麻烦了解你的问题。您是否明确提到了Halo容器Canvas?还是你命名了一个自定义组件Canvas?如果它是自定义的,如代码所示,组件内部是什么?

creationComplete是一个事件,只有当组件完成第一次运行组件生命周期创建过程时才会触发一次。您的代码片段不会显示从列表传递到画布中的任何数据,因此可能是数据为空的原因之一。

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

+0

对不起,我感到困惑。我只在这里粘贴非常基本的代码。请参阅更新的代码... – FlyingCat 2010-07-05 01:22:20

+0

我确实有主应用程序发送的数据。 productDetail组件接收数据并显示它。产品细节将根据用户在列表中点击的产品而改变。某些产品品牌为空,当用户点击无品牌产品时,我想显示No Brand ...感谢您的帮助...:D – FlyingCat 2010-07-05 01:35:52