Titanium refreshing TableView with new data

2019-07-14 18:39发布

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

2条回答
beautiful°
2楼-- · 2019-07-14 19:14

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.

查看更多
beautiful°
3楼-- · 2019-07-14 19:26

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.

查看更多
登录 后发表回答