我有一個DropdownList,顯示供應商列表&必須選擇與該Patient關聯的Provider。Flex下拉列表CreationComplete錯誤
的下拉列表:
<s:DropDownList id="providerList"
width="80%"
fontSize="12"
fontWeight="bold"
selectionColor="white"
creationComplete="providerList_creationCompleteHandler(event)"
dataProvider="{model.practiceProviderList.practiceProviders}"/>
其中practiceProviders是一個ArrayCollection
的CreationCompleteHandler功能:
protected function providerList_creationCompleteHandler(event:FlexEvent):void
{
var firstN:String;
var lastN:String;
var providerObj:Provider = new Provider();
if (model.patientDetails.patientDetail.patientProviders != null && model.patientDetails.patientDetail.patientProviders.length > 0)
{
firstN = patientDetailsModel.patientDetails.patientDetail.patientProviders.getItemAt(0).provider.providerName.firstName;
lastN = patientDetailsModel.patientDetails.patientDetail.patientProviders.getItemAt(0).provider.providerName.lastName;
for (var count:int = 0; count < patientDetailsModel.practiceProviderList.practiceProviders.length; ++count)
{
providerObj = patientDetailsModel.practiceProviderList.practiceProviders.getItemAt(count, 0).provider as Provider;
if (providerObj.providerName.firstName == firstN && providerObj.providerName.lastName == lastN)
{
this.providerList.selectedIndex = count;
}
}
}
}
的問題是,當我去這個頁面的第一次,錯誤是:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.newwavetechnologies.modules::demographics/providerList_creationCompleteHandler()[C:\harish\flex\apps\workspace\dataCollection-flexUserInterface\src\com\newwavetechnologies\modules\demographics.mxml:166]
at com.newwavetechnologies.modules::demographics/__providerList_creationComplete()[C:\harish\flex\apps\workspace\dataCollection-flexUserInterface\src\com\newwavetechnologies\modules\demographics.mxml:359]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at mx.core::UIComponent/set initialized()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1577]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:759]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]
其中線166是:
if (providerObj.providerName.firstName == firstN && providerObj.providerName.lastName == lastN)
的providerObj是空的第一次。但是,當再次回到同一頁面時,一切正常,並且列表中的一個提供者被正確選擇。
可能我第一次在創建List之前調用creationComplete處理函數。第二次調用時,列表被填充並且處理程序正常工作。如果有人能在這方面幫助我解決這個問題,那將是非常棒的。
感謝
哈里什
馬蒂感謝您的答覆,它擺脫了錯誤的。但是第一次沒有選擇提供商。下一次它。所以仍然沒有解決我的問題:(有沒有辦法來解決競爭條件。對不起,但我是新來的Flex世界! – Harry 2010-09-08 16:41:10
我已經更新了我的答案,可能的解決方案。 – 2010-09-08 17:57:20
馬蒂,謝謝。我想知道是什麼原因導致了錯誤,providerObj不是Bindable,所以我添加了這個和瞧!我將把你的答案標記爲正確的:)。非常感謝!!! – Harry 2010-09-08 18:14:36