首页 > 解决方案 > PowerBI Desktop 自定义视觉 - 存储问题

问题描述

我在 PowerBI 中为我的公司开发了 ISO 日历周的自定义过滤器。

它工作得很好,但我无法将当前过滤器保存到本地存储。它在发布时可以在网络上运行,但不能在桌面版本中运行。

import ILocalVisualStorageService = powerbi.extensibility.ILocalVisualStorageService;



constructor(options: VisualConstructorOptions){
    this.storage = options.host.storageService;
}
 

在我的第一个更新周期中,我检查本地存储并在必要时进行设置。

//to get data in async function
let cache = await this.storage.get("filter");


//to set data in async function
await this.storage.set("filter", "xyz");
 

是否可以在桌面中使用本地存储?

亲切的问候

托拜厄斯

标签: powerbi-custom-visuals

解决方案


您是否尝试联系 Power BI 视觉对象支持以激活本地存储 API,因为它默认未激活?

https://docs.microsoft.com/en-us/power-bi/developer/visuals/local-storage

或者,对于您的用例,使用persistProperties服务可能会更好。PBI Visuals 文档网站上关于此功能的文档很少,但您可以在 powerbi-visuals-sankey custom visual 中找到一个示例,它用于存储各种属性。

https://github.com/microsoft/powerbi-visuals-sankey

您的案例的粗略示例:

options.host.persistProperties({
            VisualObjectInstance = {
            objectName: "filterSetting",
            selector: undefined, 
            properties: {
                filter: "xyz"
            }
        };
     });

触发 persistProperties 函数后,视觉对象触发更新,用持久属性填充 VisualUpdateOptions 的 options.dataViews.metadata.objects。请注意,您必须事先在 capabilities.json 中定义您的属性。


推荐阅读