将数据从JSON文件放入本地存储

时间:2022-07-05 17:03:23

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

我在使用SAPUI5方面真的很新,所以我必须在这个主题上学到很多东西。这是我目前的问题:

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?

我有一个应用程序,其输入字段已经有值。这些值将写入JSON文件。应用程序用户可以更改这些输入值,并且应该能够使用保存按钮进行保存。我已经读过,用户交互无法更改JSON文件中的数据。一个人应该使用本地存储。它是如何工作的?如何将JSON文件中的数据放入本地存储?

Thanks for answering!

谢谢回答!

2 个解决方案

#1


2  

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

SAPUI5中有一个名为jQuery.sap.storage的API,您可以使用它:

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.

put和get方法已经为你做了JSON(stringify / parse)工作。

BR Chris

BR克里斯

#2


0  

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

说到'浏览器JS',本地存储可能是指这个:https://developer.mozilla.org/en/docs/Web/API/Window/localStorage

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

要保存json:window.localStorage.setItem('savedJson',yourJsonObject);

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

阅读:var loadedJson = window.localStorage.getItem('savedJson'):

#1


2  

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

SAPUI5中有一个名为jQuery.sap.storage的API,您可以使用它:

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.

put和get方法已经为你做了JSON(stringify / parse)工作。

BR Chris

BR克里斯

#2


0  

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

说到'浏览器JS',本地存储可能是指这个:https://developer.mozilla.org/en/docs/Web/API/Window/localStorage

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

要保存json:window.localStorage.setItem('savedJson',yourJsonObject);

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

阅读:var loadedJson = window.localStorage.getItem('savedJson'):