微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

未捕获承诺类型错误:无法读取未定义的属性“setCustomModal”

如何解决未捕获承诺类型错误:无法读取未定义的属性“setCustomModal”

我是 Javascript 的新手,我正在学习一些关于使用 PDFTron 显示 pdf 的教程。但是我在设置自定义属性时遇到了问题。你能告诉我哪里出错了吗?

 window.webviewerFunctions = {
      initWebViewer: function () {
          const viewerElement = document.getElementById('viewer');
          WebViewer({
              path: 'lib',initialDoc: 'lib/simpledoc.pdf',// replace with your own PDF file
          },viewerElement)
          .then((instance) => {
              instance.setTheme('dark');
              instance.disableElements(['downloadButton','printButton' ]);
              instance.disableElements(['toolbarGroup-Insert']);
             
              
          })
          .then(function(instance) {
            var modal = {
              dataElement: 'meanwhileInFinlandModal',render: function renderCustomModal(){
                var div = document.createElement("div");
                div.style.color = 'white';
                div.style.backgroundColor = 'hotpink';
                div.style.padding = '20px 40px';
                div.style.borderRadius = '5px';
                div.innerText = 'Meanwhile in Finland';
                return div
              }
            }
            instance.setCustomModal(modal);
            instance.openElements([modal.dataElement]);
            });
      }
    };

解决方法

Promise 处理程序需要返回 instance,因为这是作为输入传递给链中下一个处理程序的内容。

   .then((instance) => {
              instance.setTheme('dark');
              instance.disableElements(['downloadButton','printButton' ]);
              instance.disableElements(['toolbarGroup-Insert']);
              return instance;
          })

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。