开发者

Titanium refreshing TableView with new data

开发者 https://www.devze.com 2023-03-14 06:38 出处:网络
This is what I am trying to do: _tableView.data[0].rows[selectedPosY].children[selectedPosX].imageId = tempImageId;

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 = tempIma开发者_运维百科geUrl;  
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);


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号