如何解决TypeError: undefined is not an object (evaluating 'n._viewer.saveDocument')- React Native
当我点击保存按钮时,我收到 TypeError: undefined is not an object (evaluating '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。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。