Titanium:Picker与远程数据崩溃

时间:2012-03-03 05:26:21

标签: titanium appcelerator titanium-mobile appcelerator-mobile

我正在尝试将远程数据填充到选择器中,但它崩溃了。

这是代码:

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);
    }

这段代码有什么问题?代码适用于静态数据!!! 静态数据: -

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}
];

1 个答案:

答案 0 :(得分:0)

解决了!!!我不是为什么,但我只是在将选择器添加到视图中之前将数据分配给选择器并且它得到解决!

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