Titanium refreshing TableView with new data

爷,独闯天下 提交于 2019-12-11 03:28:10

问题


This is what I am trying to do:

_tableView.data[0].rows[selectedPosY].children[selectedPosX].imageId = tempImageId;     
_tableView.data[0].rows[selectedPosY].children[selectedPosX].image = tempImageUrl;  
Titanium.API.info("imageIdSelected:" + 
_tableView.data[0].rows[selectedPosY].children[selectedPosX].imageId + "imageSelected:" + 
_tableView.data[0].rows[selectedPosY].children[selectedPosX].image); 

The update is done on the data, but it doesn't reflect in UI table, what is missing?

I even tried doing the below as per How can I refresh my TableView in titanium? & How to resolve Titanium TableView display problem?, but it is not refreshing the UI table _tableView.setData(_tableView.data); win.add(_tableView);


回答1:


It turns out the only way to update/reload a Titanium.UI.TableView is to get a copy of the updated data (as per ones logic) and reset it in the TableView, using 'setData'. For my example, since the _tableView.data is getting updated (which could be seen through the logging statements), I could copy it using a javascript array copy function like;

var data2 =_tableView.data.slice(0); 
_tableView.setData(data2);

Although, with the above knowledge, I had restructure my code, so, I am not using this exact code, but a similar logic. But, overall, this way of updating the table doesn't seem very appealing, if there is any better way of handling this, please post, it would help a lot.




回答2:


Why are you doing _tableView.data[0].rows and then just _tableView.data when using setData?

Your _tableView.data should be an array of rows/sections. The Ti.UI.tableView object has the data property but the data should be structured as follows.

_tableView.data = [
    {title:"Row 1"},
    {title:"Row 2"}
];

What does the .rows accomplish for you when you are doing it that way, how are you using the .rows? I'm not positive but I think the _tableView.data is either no different or is invalid when trying to setData.



来源:https://stackoverflow.com/questions/6410010/titanium-refreshing-tableview-with-new-data

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