嵌套回调函数我尝试使用箭头函数,绑定函数,但在获取facebook访问令牌后函数没有触发我需要用 this.handleApiCalls 调用api这里我的代码片段
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>
}
}
答案 0 :(得分:2)
如果console.log('Access_Token:'+data.accessToken.toString())
正在运行,则只需将this.handleApiCalls
更改为this.handleApiCalls()
即可调用它。