简体   繁体   English

ParseReact.Mixin我如何侦听this.data的更改?

[英]ParseReact.Mixin how do I listen for changes to this.data?

I have a React component that observes data on a Parse server. 我有一个React组件,可以观察Parse服务器上的数据。

mixins: [ParseReact.Mixin],
observe: function() {
   var query = new Parse.Query('Item');
   return {
      items: query
   };
}

In the render method I do receive my items and that work well. render方法中,我确实收到了items ,并且效果很好。 But, I want to be able to listen for when this.data.items will change it's value. 但是,我希望能够侦听this.data.items何时更改其值。

I'm aware of the regular lifecycle methods, but in them I have no way of checking if this.data.items is the same as before the update. 我知道常规的生命周期方法,但是在其中我无法检查this.data.items是否与更新之前相同。

componentWillUpdate: function(nextProps, nextState) {},
componentDidUpdate: function(prevProps, prevState) {},

How do I do that? 我怎么做?

You mean you need a "receiving data" callback? 您的意思是您需要“接收数据”回调?
Now there are no such a callback. 现在没有这样的回调。
See this issue . 看到这个问题

You can override "_receiveData" function in class extended ParseComponent by yourself though I'm not sure it's the right way for your situation. 您可以自己在扩展的ParseComponent类中覆盖“ _receiveData”函数,尽管我不确定这是否适合您的情况。

_receiveData(name, value) {
  this.data[name] = value;
  delete this._pendingQueries[name];
  delete this._queryErrors[name];
  this.forceUpdate();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM