我正在尝试使用MobX的可观察数组填充ListView in native native,如下所示: constructor(props) { super(props) var dataSource = new ListView.DataSource({ rowHasChanged: (r1, r2) = r1 !== r2 }); let dogs = props.store.dogs; thi
constructor(props) { super(props) var dataSource = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }); let dogs = props.store.dogs; this.state = { dogs: dogs, dataSource: dataSource }; } render() { var dogs = this.state.dogs; var dataSource = this.state.dataSource.cloneWithRows(dogs); return <ListView dataSource={dataSource} renderRow={this.renderRow} /> }
但是在运行代码时,renderRow()永远不会被调用.它就像cloneWithRows()方法不知道如何克隆行.
有没有人成功做到这一点?
(而且当狗的名单中的狗的名字发生变化时,也会让它表现出来,那么列表中的单元格将会重新渲染)
更新:
更多信息在这里https://github.com/mobxjs/mobx/issues/476
请注意,切片应该在render方法中完成,而不是在构造函数中完成;您希望每次集合更改时都会发生这种情况,而不仅仅是在构建组件时.
另见:https://github.com/mobxjs/mobx/issues/476