Flex DropdownList does not show the correct values

2019-09-03 15:13发布

问题:

I have a Flex Spark dropdownList in which I need to show the Provider FirstName,LastName:

   <s:DropDownList id="providerList"
            dataProvider="{model.practiceProviderList.practiceProviders}"
    labelField="provider.providerName.firstName"/>

But the output shows only [object Object] & [object Object] as there are 2 providers in the DB and does not show the actual values.

The PracticeProviderList.as:

[Bindable]
    [RemoteClass(alias="model.PracticeProviderList")]
    public class PracticeProviderList extends PracticeProviderListBase {

        private var _practiceProviderList:ArrayCollection;

        public function get practiceProviders():ArrayCollection
        {
            return _practiceProviderList;
        }

        public function set practiceProviders(value:ArrayCollection):void 
        {
            _practiceProviderList = value;
        }

The PracticeProvider Object:

public class PracticeProvider  {

        private var _practiceId:Number;
        private var _practiceProviderId:Number;
        private var _provider:Provider;

        public function set practiceId(value:Number):void {
            _practiceId = value;
        }
        public function get practiceId():Number {
            return _practiceId;
        }

        public function set practiceProviderId(value:Number):void {
            _practiceProviderId = value;
        }
        public function get practiceProviderId():Number {
            return _practiceProviderId;
        }

        public function set provider(value:Provider):void {
            _provider = value;
        }
        public function get provider():Provider {
            return _provider;
        }

The Provider has providerName:PersonName as one of it's fields & PersonName has firstName:String & lastName:String

I need to show the First Name, Last Name in the dropdownlist. I would appreciate if someone can help in this regard.

Thanks

Harish

回答1:

The labelField can't concatenate 2 values. Use a labelFunction instead.

If I understand your data model, Something like this:

public function myLabelFunction(item:Object):String{
 return item['providerName']['PersonName']['firstName'] + ' ' + item['providerName']['PersonName']['lastName']
}