我有一个 React 组件,用于观察 Parse 服务器上的数据。
mixins: [ParseReact.Mixin],
observe: function() {
var query = new Parse.Query('Item');
return {
items: query
};
}
在render
方法中,我确实收到了我的items
并且效果很好。但是,我希望能够监听 this.data.items
何时更改其值。
我知道常规的生命周期方法,但在它们中我无法检查 this.data.items
是否与更新之前相同。
componentWillUpdate: function(nextProps, nextState) {},
componentDidUpdate: function(prevProps, prevState) {},
我该怎么做?
最佳答案
您的意思是您需要“接收数据”回调?
现在没有这样的回调。
看这个issue .
您可以自己重写类扩展 ParseComponent 中的“_receiveData”函数,尽管我不确定这是否适合您的情况。
_receiveData(name, value) {
this.data[name] = value;
delete this._pendingQueries[name];
delete this._queryErrors[name];
this.forceUpdate();
}
关于javascript - ParseReact.Mixin 如何监听 this.data 的更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32255922/