Titanium:如何在聚焦时重新加载选项卡?

发布于 2024-10-31 07:37:17 字数 772 浏览 3 评论 0原文

我在我的应用程序中构建了一个收藏选项卡,用于显示数据库中标记为此类的条目。在背面,这可以正常工作,但我不知道如何在更改后重新加载“收藏夹”选项卡。当我退出并重新启动应用程序时,更新会按预期显示。

本质上,我遇到了与这里提出的相同的问题: http: //developer.appcelerator.com/question/31211/tab---tableview--database-reload

<块引用>

“我的应用程序中有一个“搜索”和“搜索历史记录”选项卡。在此选项卡下执行的每个搜索都会插入到我的本地数据库中。 但是,当我在搜索后浏览到“搜索历史记录”选项卡时,新的搜索并未反映在从数据库检索数据的表格视图中。 然而,当我退出应用程序并重新启动它时,会加载最新的搜索。 我需要一些帮助来弄清楚如何在不退出应用程序的情况下触发表格视图重新加载。 解决方案更新: 我觉得问这个问题很“菜鸟”,但它真的很简单 我为包含选项卡的窗口添加了一个“焦点”事件监听器来加载数据。 win.addEventListener('focus', function() { loadDBdata(); });

这看起来很合理,但是 loadDBdata 函数应该包含什么内容? 我将非常感谢任何对此的指示。

I have built a favorite-tab in my application that displays entries in a database that are flagged as such. On the backside this works as it should, but I can't figure out how to reload the favorites tab after changes have been made. When I quit and relaunch the app though, the updates appear as they should.

In essence I have the same problem as is presented here: http://developer.appcelerator.com/question/31211/tab---tableview--database-reload

"I have a 'search' and 'search history' tab in my application. Every search executed under this tab gets inserted into my local db.
However the new search is not reflected in the tableview retrieving data from the DB in the 'search history' tab when i browse to it, after searching.
The latest search, however, gets loaded when I exit the app and relaunch it.
I need some help in figuring out how to trigger the tableview reload without exiting the app.
SOLUTION UPDATE:
I feel 'noobish' for asking this question but it was really so simple
I added a 'focus' eventlistener for the window housing the tab to load the data.
win.addEventListener('focus', function() { loadDBdata(); });

This seems reasonable, but what should the loadDBdata function should contain?
I would greatly appreciate any pointers to this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的十字路口 2024-11-07 07:37:17

我建议在更新收藏夹时触发一个事件,并在保存收藏夹列表的桌子上放置一个事件侦听器。当它收到事件时,它应该更新表内容。

看到这个问题我刚刚回答它应该提供解决您的问题的指南

Appcelerator 中页面刷新功能出现问题

i would suggest firing an event when the favorites are updated and having an event listenter on the table that holds the favorites list. When it receives the event, it should update the tables contents.

see this question I just answered it should provide a guide for solving your problem also

Problems with refresh function for page, in Appcelerator

马蹄踏│碎落叶 2024-11-07 07:37:17

loaddb 函数应包含以下内容:

// init database
var db = Ti.Database.install('path/to/database.db','myDB');

// your request
var sql = 'SELECT * FROM myDatabaseTable';

// the result from that request
var myContent = db.execute(sql);

// need to put the result in a valid structure before inserting into your tableview
var data = [];
while (myContent.isValidRow()){
  // your tableviewrow
  var row = {
    title = myContent.field(0);
  };
  data.push(row);
  myContent.next();
};

// need to close stuff (!)
myContent.close();
db.close();

// finally return data
return data;

the loaddb function should contain something like:

// init database
var db = Ti.Database.install('path/to/database.db','myDB');

// your request
var sql = 'SELECT * FROM myDatabaseTable';

// the result from that request
var myContent = db.execute(sql);

// need to put the result in a valid structure before inserting into your tableview
var data = [];
while (myContent.isValidRow()){
  // your tableviewrow
  var row = {
    title = myContent.field(0);
  };
  data.push(row);
  myContent.next();
};

// need to close stuff (!)
myContent.close();
db.close();

// finally return data
return data;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文