Search code examples
titaniumappceleratortitanium-mobileappcelerator-mobile

Titanium: Picker crashes with remote data


I am trying to fill remote data into picker, but it crashes.

here is the code:

var countryDataArray = []; 
var picker_country = Ti.UI.createPicker
({
    bottom:'-251dp'
});
win.add(picker_country);
getCountryList(); //to call web service

//Gets country list from the server
function getCountryList()
{
getCountry.onload = function()
    {
        var jsonString = JSON.parse(this.responseText);
        var msg = jsonString.Message;
        var success = jsonString.IsSuccess;

        countryDataArray = jsonString.dsetData.CountryList;

        Ti.API.log('countryList value:'+countryDataArray);
        activity.hide();

        if(countryDataArray.length > 0)
        {
            for (var i=0; i < countryDataArray.length ; i++) 
            {
                 data[i] = Ti.UI.createPickerRow(
                 {
                    title:countryDataArray[i].Name, 
                    country_id:countryDataArray[i].ID,
                    fontSize:18
                 });
             };
        }   
        picker_country.add(data);
    }

what's wrong with this code ? code works fine with static data !!! static data :-

var data = [
    {title:'Bananas',custom_item:'b',fontSize:18},
    {title:'Strawberries',custom_item:'s',fontSize:20},
    {title:'Mangos',custom_item:'m',fontSize:22,selected:true},
    {title:'Grapes',custom_item:'g',fontSize:24}
];

Solution

  • Solved !!! I Don't why but I just assign the data to picker before adding the picker into the view and it get solved !

    picker_country.add(data);
    win.add(picker_country);