0
我想在用戶拍照後調用一個函數。我嘗試通過以下方式來完成:裏面的React-Native調用函數。異步函數
export default class LA extends Component {
constructor(props) {
super(props);
this.doSomething = this.doSomething.bind(this);
}
takePicture() {
this.camera.capture()
.then(function(data) {
doSomething(data.path); //THIS CAUSES THE RUNTIME ERROR
})
.catch(err => console.error("error: " + err));
}
doSomething(imgPath) {
console.log(imgPath);
}
}
而且拍照的時候,我得到了以下錯誤:
error: Reference Error: doSomething is not defined
但是,如果我更換takePicture()有:
takePicture() {
this.camera.capture()
.then(function(data) {
console.log(data.path);
})
.catch(err => console.error("error: " + err));
}
圖像路徑被記錄,並且沒有發生錯誤。
非常感謝您的幫助! – user7639007