Titanium 未插入行

Titanium 未插入行,titanium,tablerow,titanium-mobile,Titanium,Tablerow,Titanium Mobile,我得到了正确的JSON响应,但我的问题是如何显示它。我的代码有什么问题 // this sets the background color of the master UIView (when there are no windows/tab groups on it) Titanium.UI.setBackgroundColor('#000'); // create base UI tab and root window var win1 = Titanium.UI.createWind

我得到了正确的JSON响应,但我的问题是如何显示它。我的代码有什么问题

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
 Titanium.UI.setBackgroundColor('#000');

// create base UI tab and root window

var win1 = Titanium.UI.createWindow({
title : 'Main Window',
backgroundColor : '#fff'
 }); 

 var listUrl = "http://magadhena.com/test/list.php?FCODE=5&USERID=1";
 var NumberOfLists = [];
 var lists;
 var tableData = [];
 var table = Ti.UI.createTableView({
top : 40,
left : 10,
width : 300
});
var txt1 = Titanium.UI.createTextField({

top : 10,
left : 10,
width : 250

 });
 var button1 = Ti.UI.createButton({
top : 10,
left : 270,
width : 30

});

 var xhr = Ti.Network.createHTTPClient();
xhr.setTimeout(3000);
xhr.onload = function() {
lists = eval('(' + this.responseText + ')');
for(var i = 0; i < lists.length; i++) {
    var userId = lists[i].userid;
    // The userID
    var listId = lists[i].listid;
    // The ListID
    var listName = lists[i].listname;
    // The ListName

    var Object1 = new list(userId, listId, listName);

    // Ti.API.log("Object is ",Object1.listId);
    NumberOfLists.push(Object1);
    // Ti.API.log("the size of the Json array is" , NumberOfLists.length);
}
};
xhr.open("GET", listUrl);
xhr.send();

for(var i = 0; i < NumberOfLists.length; i++) {

var row = Ti.UI.createTableViewRow({
    title : NumberOfLists[i].listName
});
Ti.API.log("populating the data table ", NumberOfLists[i].toString);
tableData.push(row)

};

//  Ti.API.log("the size of table data is ", tableData.length);
table.setData(tableData);

win1.add(table);
win1.add(txt1);
win1.add(button1);

// Opening Window1

win1.open();

///// List Objects

function list(userid, listid, listname) {
this.userId = userid;
this.listId = listid;
this.listName = listname;

}
//设置主UIView的背景色(当主UIView上没有窗口/选项卡组时)
钛.UI.setBackgroundColor('#000');
//创建基本UI选项卡和根窗口
var win1=Titanium.UI.createWindow({
标题:“主窗口”,
背景颜色:“#fff”
}); 
var listUrl=”http://magadhena.com/test/list.php?FCODE=5&USERID=1";
var NumberOfLists=[];
var列表;
var tableData=[];
var table=Ti.UI.createTableView({
前40名,
左:10,,
宽度:300
});
var txt1=Titanium.UI.createTextField({
前10名,
左:10,,
宽度:250
});
var button1=Ti.UI.createButton({
前10名,
左:270,
宽度:30
});
var xhr=Ti.Network.createHTTPClient();
xhr.setTimeout(3000);
xhr.onload=函数(){
lists=eval('('+this.responseText+');
对于(变量i=0;i
您需要将table.setData()放入xhr.onload函数中。由于您在函数外部定义了代码,NumberOfList在执行xhr.onload函数之前为空