【发布时间】:2016-04-11 22:08:16
【问题描述】:
我尝试使用ddp 驱动程序从react-native 订阅meteor。在componentDidMount 期间,它给了我例外
Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op.
这是我的代码
getInitialState: function() {
return {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => !_.isEqual(row1, row2),
}),
loaded: false,
};
},
componentDidMount: function() {
console.log('component mounted');
console.log(this.props['actor']);
ddp.initializeWithSubscribe(() => {
ddp.subscribe('select-all-meals-by-restaurant', [this.props['actor']['obj']['_id']]);
});
var ddpClient = ddp.connection;
var observer = ddpClient.observe('meals');
observer.added = () => this.updateRows(_.cloneDeep(_.values(ddpClient.collections.meals)));
observer.changed = () => this.updateRows(_.cloneDeep(_.values(ddpClient.collections.meals)));
observer.removed = () => this.updateRows(_.cloneDeep(_.values(ddpClient.collections.meals)));
},
/*------------------------------------------------------------------------------
* Util function for watching data
*-----------------------------------------------------------------------------*/
updateRows: function(rows) {
console.log('rows :' + rows);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(rows),
loaded: true,
});
},
你能建议我解决这个问题的方法吗?
【问题讨论】:
-
一切对我来说似乎都是完美的:|
标签: meteor react-native