Titanium在tableview中显示表中的数据

Titanium display the datas from the table in tableview

本文关键字:数据 显示 tableview Titanium      更新时间:2023-09-26

我是钛的新手。。我已经创建了一个表视图,我想在创建的标签和表视图形式中显示数据库中的数据,但无法实现。

代码:

var triplistview = Titanium.UI.createTableView({
    backgroundColor : 'white',
    width : Titanium.UI.FILL,
    height : Ti.UI.SIZE,
    layout : 'horizontal',
    padding : '10dp',
    separatorColor : theme_background
    // margin:'10dp',
});
scrollView.add(triplistview);
var data = [];
    var db = Titanium.Database.open('trip');
    db.execute('CREATE TABLE IF NOT EXISTS newtrip (id INTEGER PRIMARY KEY AUTOINCREMENT, triplabel TEXT,tripname TEXT,destination TEXT,fromdate TEXT,todate TEXT)');
    while (resultrows.isValidRow()) {
            var row = Ti.UI.createTableViewRow({
            height : Ti.UI.SIZE,
            rightImage : '/images/right1.png',
            layout : 'absolute',
            //title :  '' + 'Destination' + '' + '' + resultrows.fieldByName('destination') + '' + 'From Date:' + '' + '' + resultrows.fieldByName('fromdate') + '' + 'To Date:' + '' + resultrows.fieldByName('todate')
        });
        row.add(tripnamelabel);
        row.add(buttonedit);
        row.add(buttondelete);
        row.add(fromdate);
        row.add(dash);
        row.add(todate);
        triplistview.add(row);
    row.className = 'control';
        data.push(row);
        resultrows.next();
    }
    triplistview.setData(data);
    resultrows.close();
    db.close();

这些是我创建的标签

 var tripnamelabel = Ti.UI.createLabel({
    text:resultrows.fieldByName('destination'),
    color : theme_style,
    font : {
        fontSize : '15dp',
        fontWeight : 'bold'
    },
    top : '10dp',
    left : '10dp',
});
 var buttonedit = Ti.UI.createButton({
    backgroundImage : '/images/list_edit.png',
    top : '20dp',
    width : wb,
    height : hb,
    right : '20dp'
});
var buttondelete = Ti.UI.createButton({
    backgroundImage : '/images/delete_ic.png',
    top : '20dp',
    width : wb,
    height : hb,
    right : '60dp'
});
var fromdate = Ti.UI.createLabel({
    text:resultrows.fieldByName('fromdate') 
    color : 'Black',
    font : {
        fontSize : '13dp',
        fontWeight : 'bold'
    },
    top : '40dp',
    left : '10dp',
    right : '10dp',
    bottom : '20dp'
});
var dash = Ti.UI.createLabel({
    text : '-',
    color : 'Black',
    font : {
        fontSize : '15dp',
        fontWeight : 'bold'
    },
    top : '40dp',
    left : '80dp',
    right : '10dp',
    bottom : '20dp'
});
var todate = Ti.UI.createLabel({
    text:resultrows.fieldByName('todate') 
    color : 'Black',
    font : {
        fontSize : '13dp',
        fontWeight : 'bold'
    },
    top : '40dp',
    left : '90dp',
    right : '10dp',
    bottom : '20dp'
});

请帮助我,因为我已经被困了一天多了,我收到了这个错误

[ERROR]应用程序安装程序进程异常终止。进程退出值为1

我看到的一个问题是,您没有为结果行分配任何内容。

没有针对数据库的查询,类似

var resultrows = db.execute('SELECT * FROM newtrip');
while (resultrows.isValidRow()) { ...

我不知道你是如何进入while循环来显示你的文本的:正如你所说的"嗨"。

这个错误似乎与您应该看到的不匹配。想知道是否删除了太多的代码来帮助这个例子。