TypeError: undefined 不是对象(评估 'n._viewer.saveDocument')- React Native



我得到TypeError:当我单击保存按钮时,undefined不是一个对象(正在评估"n._viewer.saveDocument"(。我认为保存文档的文件路径没有通过覆盖层内部。我可能错了。有人能告诉我我在这里做错了什么吗?

render() {
var filepath;
if (this.props.dsType == "fileDocument") {
if (path == fileContent.value) {
filepath = path.uri;
} else {
<h1>Unable to render document.</h1>;
}
} 
//value in filepath
console.info("filepath =", filepath);
return (
<View style={{ flex: 1 }}>
<DocumentView
//ref={(c) => this._viewer = c}
document={filepath}
onDocumentLoaded={path => {
console.info("The document has finished loading:", path);
}}
/>
<View style={styles.button}>
<Button
onPress={() => {
// Manual Save
this._viewer.saveDocument().then((filePath) => {
console.log('saveDocument:', filePath);
});
}}
title="Save"
/>
</View>
</View>
);
}
return null;
}

您似乎已经注释掉了应该分配查看器实例的行。如前所述,应该取消对该行的注释,以便为this._viewer分配引用。如果您不确定,可以参考GitHub上的示例代码:https://github.com/PDFTron/pdftron-react-native/blob/e19b4970357f9ed2443696eb989f1c91c1905911/example/App.js#L82.

最新更新