Titanium 使用新数据刷新 TableView [英] Titanium refreshing TableView with new data
问题描述
这就是我想要做的:
_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);
对数据进行了更新,但未反映在UI表中,缺少什么?
The update is done on the data, but it doesn't reflect in UI table, what is missing?
我什至尝试按照 如何刷新我的钛表视图? &如何解决Titanium TableView的显示问题?,但是不刷新用户界面表_tableView.setData(_tableView.data);win.add(_tableView);
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);
推荐答案
事实证明,更新/重新加载 Titanium.UI.TableView 的唯一方法是获取更新数据的副本(根据逻辑)并重置它在 TableView 中,使用setData".对于我的示例,由于 _tableView.data 正在更新(可以通过日志记录语句看到),我可以使用 javascript 数组复制函数复制它;
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.
这篇关于Titanium 使用新数据刷新 TableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!