react-native:嵌套回调如何绑定方法
问题描述:
嵌套回调函数我尝试过使用箭头函数,绑定函数,但功能没有触发后得到Facebook访问令牌我需要调用API与this.handleApiCalls这里我的代码片断react-native:嵌套回调如何绑定方法
const FBSDK = require('react-native-fbsdk')
const {
LoginButton,
AccessToken
} = FBSDK
class LoginScreen extends React.Component {
constructor() {
super(props)
}
handleApiCalls =() => {
alert("handle the api calls");
}
render() {
return <View style={{justifyContent: 'center',
alignItems: 'center'}}>
<LoginButton
publishPermissions={['publish_actions']}
onLoginFinished={
// first call back
(error, result) => {
if (error) {
console.log('error:', error);
} else if (result.isCancelled) {
alert('login is cancelled.')
console.log('login is cancelled:', result);
} else {
// second callback
AccessToken.getCurrentAccessToken().then((data) => {
console.log('Access_Token:'+data.accessToken.toString())
// ================ how to call this function ===============
this.handleApiCalls
})
}
}
}
onLogoutFinished={() => alert('logout.')}/>
</View>
}
}
答
如果console.log('Access_Token:'+data.accessToken.toString())
工作则只是改变this.handleApiCalls
到this.handleApiCalls()
来调用它。