0

I am looking for correct and decent way of storing favorites articles in my app to phone storage. I built the app with Web shop articles listed and I would like to allow users to save favorite articles to the "favorite" list.

I have tried application-settings plugin and I am not sure is this a good way of doing it because keys needs to be predefined. (I am not really sure). Is there a some kind of JSON style data storage which does work on Android and iOS? - It would be great because I could sync it to Cloud storage at some point.

I need a easy way for manipulating data, add, remove, clear the list. Something what will not impact app performance. Cheers guys.

4

1 回答 1

1

完全由您选择以下之一。我会说你应该对application-settings自己好。

应用程序设置仍然是一个快速而好的选择。

function getFavorites() {
  return applicationSettings.getString("favorites", "[]");
}

function setFavorites(data) {
  return applicationSettings.setString("favorites", JSON.stringify(data));
}

let data = getFavorites();

// Add new
data.push({
    id: "NewFavId",
    ... // other attributes
});

// Delete existing one
data = data.filter((item) => item.id === "IdToDelete");


// Update application settings
setFavorites(data);

nativescript-localstorage是另一个类似的选项,它在内部使用 JSON 文件来存储数据。

说到在设备上存储数据,nativescript-sqlite也在那里,但您可能不需要它来进行像您这样的简单数据操作或nativescript-secure-storage,这也是另一种选择,但仅用于存储高度敏感的信息。

于 2019-02-02T06:56:41.253 回答