React - 可观察对象中的 setState

React - setState in an observable

我有一个数组

    let exams = []
and an observable

    stream.subscribe(
       function onNext(patients) {
           let patient = patients[0]
           await exams.push({
               patient,
               session
           })
           // this.setState(exams)
       }, function onError(error) {
            console.log('error',error)
       }, function onComplete() {
           console.log("exams",exams)
       });

现在在onNext函数中,我想调用setState。

数组在 observable 之后为空,并且由于某种原因,无法从 observable 内部调用 setState。

关注

let that = this
    stream.subscribe(
   function onNext(patients) {
       let patient = patients[0]
       await exams.push({
           patient,
           session
       })
       that.setState({exams})
   }, function onError(error) {
        console.log('error',error)
   }, function onComplete() {
       console.log("exams",exams)
   });

使用let that = this