首页 > 解决方案 > 在 React 中嵌入 Power Bi 中捕获书签

问题描述

我正在尝试在我们的应用程序中实现书签捕获功能。我克隆了https://github.com/howlowck/react-powerbi库以使用此类功能对其进行扩展。基于 MS Demo 和文档,bookmarksManager 对象上有一个 .capture() 方法。这是我试图访问它的代码修改(这个库的文件 index.js):

componentDidUpdate () {
    if (this.validateConfig(this.state)) {
      this.embed(this.state)
      console.log(this.component.bookmarksManager)
      getBookmark(this.component)
  }
}
...
function getBookmark(power){
  console.log('inside getBookmark')
  console.log(power.bookmarksManager.capture)
 power.bookmarksManager.capture().then (function (capturedBookmark){
    alert('inside callback')

  });
  console.log('passed test')
      
    }

运行时 - console.log 显示“内部书签”也显示捕获功能,但从未执行回调。(也没有任何未捕获的承诺拒绝)任何有用的想法?

该函数存在于库中:

BookmarksManager.prototype.capture = function () {
            if (utils.isRDLEmbed(this.config.embedUrl)) {
                return Promise.reject(errors.APINotSupportedForRDLError);
            }
            return this.service.hpm.post("/report/bookmarks/capture", null, { uid: this.config.uniqueId }, this.iframe.contentWindow)
                .then(function (response) { return response.body; }, function (response) {
                throw response.body;
            });
        };

标签: reactjspowerbi-embedded

解决方案


在包括 powerbi.js 文件在内的彻底调试之后,似乎调用被提前并且配置为空,导致 { uid: this.config.uniqueId } 未定义。放置在组件下的相同函数将成功调用卸载。可能必须以接受回调作为道具的方式修改库。这个回调应该接受“power”对象。成功嵌入后,父组件可以捕获和/或在某些按钮操作上应用书签。


推荐阅读