【问题标题】:How to create a TableView with the rows displaying a value from an SQLite database in Titanium Studio?如何在 Titanium Studio 中使用显示 SQLite 数据库中的值的行创建 TableView?
【发布时间】:2013-01-24 09:01:46
【问题描述】:

我正在尝试使用 Titanium Studio 创建一个应用程序,该应用程序将显示来自 SQLite 数据库的信息。 为了使事情更简单,假设我的数据库具有以下列: 姓氏、名字、年龄、种族和宗教

我目前有一个应用程序的基本框架,它由多个选项卡组成。 在其中一个选项卡(对应于特定窗口)中,我希望有一个 TableView,每行仅显示 Last Name, Given Name & Age

我该怎么做? 感谢我能得到的所有帮助!

谢谢!

【问题讨论】:

  • 首先,让我们知道您是否可以创建数据库,是否可以创建一些数据库条目,是否可以从中检索数据库。你能创建 TableView 吗?
  • 嘿!我使用 SQLite 创建了一个数据库,并使用该程序将一些数据输入到该数据库中。然后我就可以使用 install database 方法安装数据库了。
  • 另外,我能够创建 tableview,只是我不知道如何在 TableViewRows 中显示数据库中的值

标签: database sqlite titanium


【解决方案1】:

Have you looked at this?

因此,一旦您从数据库中获取了行,只需为您的 tableview 创建行。这是一个开始:

// Fetch the db and execute a select from your person table
var db = Ti.Database.open('mydb');
var rows = db.execute('SELECT * FROM person');

var persons = [];
while (rows.isValidRow())
{
    persons.push({title : + rows.fieldByName('Last Name'));
    rows.next();
};
rows.close();

var yourTable = Ti.UI.createTableView({
    width : Ti.UI.FILL,
    height : Ti.UI.FILL,
    data: persons // Set the rows to the table
});

// Dont forget to close the db
db.close();

Use this as a reference to style your table rows more effectively.

【讨论】:

    猜你喜欢
    • 2015-01-07
    • 1970-01-01
    • 2013-10-06
    • 2020-01-27
    • 2014-10-16
    • 1970-01-01
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多