如何在webview的onmessage中调用道具

时间:2020-04-15 05:14:45

标签: react-native react-native-webview

使用onmessage函数,我已经从webview接收了数据,并且我想存储这些数据,例如。在reducer中缓存值,因此我需要在onmessage内调用道具

在这里,我将接收到的数据存储在数组中并将该数组传递到this.props.cmidata({'value':cmidataArray}),但是我未定义错误不是对象(评估this.props)

<WebView
        source={Platform.OS === 'ios' ?
        { uri: RNFS.LibraryDirectoryPath + "/offlineplayer/index.html" } :
        { uri: 'file:///android_asset/offlineplayer/index.html' }
      }
          ref={(webView) => this.webView = webView}
          originWhitelist={["*"]}
         javaScriptEnabled={true}
         domStorageEnabled={true}
          startInLoadingState={true}
          useWebKit={true}
          onLoad={() => this.sendPostMessage()}
          onMessage={this.onMessage}
          allowFileAccess={true}
         />

 onMessage() {
    objcache = event.nativeEvent.data
     var cache = JSON.parse(objcache)

    //code to store the value in reducer
   var cmidataArray = []
  let cmidatavalues = {
    course_code: this.state.id,
    onlineCmidataJsonObjectList: cache
  }
  cmidataArray.push(cmidatavalues)

this.props.cmidata({ 'value': cmidataArray })

}

0 个答案:

没有答案