Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Storage Type undefined

I used a jQuery storage to store data.

oStore = jQuery.sap.storage(jQuery.sap.storage.Type.local);
oStore.put("id", rep);

but I am getting this error:

Cannot read property 'Type' of undefined

Can you please help?

like image 271
simon Avatar asked Jun 21 '26 17:06

simon


1 Answers

UI5 version 1.58+

The module sap/ui/util/Storage, which is available since UI5 1.58, replaces jQuery.sap.storage.

sap.ui.define([
  "sap/ui/util/Storage",
  // ...
], function(Storage/*,...*/) {
  "use strict";
  const storageType = Storage.Type.local;
  const storage = new Storage(storageType);
  // ...
});

API reference: sap/ui/util/Storage

UI5 version < 1.58 (Previous answer)

The reason, why jQuery.sap.storage is not defined, is that the module has not yet been loaded (and thus not globally accessible). Whenever you're using jQuery APIs, make sure to resolve its dependency first, and then use the resolved parameter name instead of accessing APIs globally as mentioned in the documentation:

Use only local variables inside the AMD factory function, do not access the content of other modules via their global names, not even for such fundamental stuff like jQuery or sap.ui.Device. You can't be sure that the modules are already loaded and the namespace is available.

Example:

sap.ui.define([
  "jquery.sap.storage",
  // ...
], function(jQuery/*,...*/) {
  "use strict";
  const storageType = jQuery.sap.storage.Type.local;
  const storage = jQuery.sap.storage(storageType);
  // ...
});

UI5 API Reference jquery.sap.storage

API reference: jquery.sap.storage

like image 82
Boghyon Hoffmann Avatar answered Jun 23 '26 08:06

Boghyon Hoffmann