简体   繁体   中英

Put data from JSON file into local storage

I'm really new in working with SAPUI5 so I have to learn a lot in this topic. This is my current problem:

I have an application with input fields which have already values. These values are written into an JSON file. The app user can change these input values and should be able to save them using a save button. I've read that it isn't possible to change data in an JSON file by an user interaction. One should use local storage. How does it work? How can I put data from JSON file into this local storage?

Thanks for answering!

There is an API in SAPUI5 already called jQuery.sap.storage and this is how you use it:

Store Data

var oStore = jQuery.sap.storage(jQuery.sap.storage.Type.local);
oStore.put("id", { test: "test" });

Retrieve Data

var oStore = jQuery.sap.storage(jQuery.sap.storage.Type.local);
var oDate = oStore.get("id");

The put and get methods already do the JSON (stringify/parse) work for you.

BR Chris

Speaking of 'browser JS', local storage may be referring to this: https://developer.mozilla.org/en/docs/Web/API/Window/localStorage

To save json: window.localStorage.setItem('savedJson', yourJsonObject);

To read: var loadedJson = window.localStorage.getItem('savedJson'):

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