最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Problems with refresh function for page, in Appcelerator - Stack Overflow

programmeradmin1浏览0评论

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:

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/1778830

Share Improve this question edited Nov 25, 2011 at 2:50 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked Apr 10, 2011 at 13:45 Jonathan ClarkJonathan Clark 20.6k29 gold badges116 silver badges177 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

this is a mon 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);

发布评论

评论列表(0)

  1. 暂无评论