简体   繁体   中英

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?

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);
  // ...
});

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM