本機存放區 APILocal Storage API

本機存放區 API 是自訂視覺效果可用以要求主機在裝置存放區儲存或載入資料的 API。The Local Storage API is an API a custom visual can use to request the host to save or load data from the device's storage. 為區隔不同視覺效果類型之間的存放區存取權,所以予以隔離。It's isolated in the sense that there's separation of storage access between different visual types.

範例Sample

如果自訂視覺效果在每次呼叫 update 方法時都應增加一些計數器,卻又應該保留計數器值,且不在每次視覺效果啓動時重設:If the custom visual should increase some counter every time the update method is called, but the counter value should also be preserved and not reset on every visual start:

export class Visual implements IVisual {
        // ...
        private updateCountName: string = 'updateCount';
        private updateCount: number;
        private storage: ILocalVisualStorageService;
        // ...

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

            this.storage.get(this.updateCountName).then(count =>
            {
                this.updateCount = +count;
            })
            .catch(() =>
            {
                this.updateCount = 0;
                this.storage.set(this.updateCountName, this.updateCount.toString());
            });
            // ...
        }

        public update(options: VisualUpdateOptions) {
            // ...
            this.updateCount++;
            this.storage.set(this.updateCountName, this.updateCount.toString());
            // ...
        }
}

已知限制及問題Known limitations and issues

根據預設,不會針對 Power BI 視覺效果啟動本機存放區 API。Local Storage API isn't activated for Power BI visuals by default. 如果想要針對自己的 Power BI 視覺效果啟動該 API,請將要求傳送給 Power BI 視覺效果支援 pbicvsupport@microsoft.comIf you want to activate it for your Power BI visual, send a request to Power BI visuals Support pbicvsupport@microsoft.com.
請注意,您的視覺效果應該在 AppSource 中提供,且 經過認證Please note that your visual should be available in AppSource and be certified.