来自 MobX 商店的 React Native ListView 中未呈现的行

Rows not rendering in React Native ListView from MobX store

我正在尝试在 React Native (0.33) 中呈现带有 headers 部分的 ListView,并且正在呈现 headers 部分而不是行。数据来自 mobx 商店。

事实证明,ListView 试图通过调用 Object.keys(...) 并期望一个整数数组(即数组索引)来找出它自己的 rowIndices,但它不适用于 ObservableArrays。

我的解决方案是,当你 cloneWithRowsAndSections 时,你可以使用 .slice() 更改为普通数组,然后像这样轻松获取节 ID:

  dataSource: ds.cloneWithRowsAndSections(
    list,
    Object.keys(list),
    Object.keys(list).map((sectionID) => Object.keys(list[sectionID].slice()))),