问题描述
钛SDK版本:1.6.1 iPhone SDK版本:4.2
我正在使用JavaScript.
我正在开发一个正在从API获取信息的应用程序.在此应用程序中,在此页面上,我得到了两种"令人耳目一新"的内容.当窗口聚焦时,当我点击"刷新"按钮时.
问题是,每次我完成页面的新鲜时,都会在新内容下的内容"副本".就像该应用程序只是在每个新鲜的其他内容上都在其他内容的新副本上进行分层.
我在代码中做错了什么?是否有一种方法可以在每个刷新之前"清除"页面.我可以想像一下这个问题会吃掉很多记忆.
您可以在此处找到我的页面: http://pastie.org/17788830
推荐答案
这是一个常见的架构问题,您应该将创建表和加载表数据的功能分开.
创建窗口时,您可以创建一次表,然后多次将数据加载到表中.下面的伪代码应为您提供基本想法.
var win = Ti.Ui.currentWindow; (function(){ var table; // create the table function initializeWindow() { } // load the data, and update table function loadWindowData() { } initializeWindow(); loadWindowData(); // called whenever you want to update window data. Ti.App.addEventListener('app:refreshTable',loadWindowData); )();
其他推荐答案
tableview -
table.setData([]); // First Clear
table.setData(tableData); // Updated Content
listView -
listView.sections[0].setItems([]);//First Clear
listView.sections[0].setItems(tableData); // Updated Content
用于更新窗口内部的内容您可以使用"打开"侦听器.
win.addEventListener("open",loadData);
问题描述
Titanium SDK version: 1.6.1 iPhone SDK version: 4.2
I am using JavaScript.
I am developing an app that is fetching information from an API. In this app, on this page, I got two ways of "refreshing" the content. When the window is focused and when I tap the refresh button.
The problem is every time I do a fresh of the page there is a "copy" of the content under the new content. It is like the app just keeps layering on new copies of the content on top of the others on each fresh.
What am I doing wrong in my code? Is there a way to "clear" the page before each refresh. I can imaging that this issue eats a lot of memory.
You can find my code for the page here: http://pastie.org/1778830
推荐答案
this is a common architectural problem, you should separate out the function of creating the table and loading the table's data.
you create the table once when the window is created, and you load the data in the table multiple times. Pseudo code below should give you the basic idea.
var win = Ti.Ui.currentWindow; (function(){ var table; // create the table function initializeWindow() { } // load the data, and update table function loadWindowData() { } initializeWindow(); loadWindowData(); // called whenever you want to update window data. Ti.App.addEventListener('app:refreshTable',loadWindowData); )();
其他推荐答案
TableView -
table.setData([]); // First Clear
table.setData(tableData); // Updated Content
ListView -
listView.sections[0].setItems([]);//First Clear
listView.sections[0].setItems(tableData); // Updated Content
For Updating Content inside Window you can use "open" listener.
win.addEventListener("open",loadData);