【问题标题】:Titanium refreshing TableView with new dataTitanium 用新数据刷新 TableView
【发布时间】:2011-09-18 14:17:39
【问题描述】:

这就是我想要做的:

_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 表中,缺少什么?

我什至尝试按照How can I refresh my TableView in titanium?How to resolve Titanium TableView display problem? 执行以下操作,但它没有刷新 UI 表 _tableView.setData(_tableView.data); win.add(_tableView);

【问题讨论】:

    标签: refresh titanium tableview


    【解决方案1】:

    事实证明,更新/重新加载 Titanium.UI.TableView 的唯一方法是获取更新数据的副本(根据逻辑)并使用“setData”在 TableView 中重置它。对于我的示例,由于 _tableView.data 正在更新(可以通过日志记录语句看到),我可以使用 javascript 数组复制函数来复制它,例如;

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

    虽然,根据上述知识,我已经重组了我的代码,所以,我没有使用这个确切的代码,而是一个类似的逻辑。但是,总的来说,这种更新表格的方式似乎不是很吸引人,如果有更好的处理方式,请发布,这将有很大帮助。

    【讨论】:

      【解决方案2】:

      为什么在使用setData 时使用_tableView.data[0].rows,然后只使用_tableView.data

      您的_tableView.data 应该是一个行/节数组。 Ti.UI.tableView 对象具有 data 属性,但数据的结构应如下所示。

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

      当您这样做时,.rows 为您完成了什么,您如何使用.rows?我不是很肯定,但我认为_tableView.data 在尝试setData 时要么没有区别,要么无效。

      【讨论】:

      • 我一直在尝试不同的方法来使代码正常工作。使用我上面的代码,语句“Titanium.API.info..”显示数据正在更新,但它不会更新 _tableView。如何更新 TableView 中的特定行/单元格并刷新 UI 中的表格?你能举个例子吗?
      猜你喜欢
      • 2017-09-22
      • 2017-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-20
      • 2015-10-03
      • 2018-05-28
      相关资源
      最近更新 更多