2010-07-04 106 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