Problems with refresh function for page, in Appcelerator

拥有回忆 提交于 2019-12-01 06:25:46

问题


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


回答1:


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);
)();



回答2:


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);



来源:https://stackoverflow.com/questions/5612136/problems-with-refresh-function-for-page-in-appcelerator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!