【问题标题】:How to store the data in local device using JSONStore in worklight?如何在 Worklight 中使用 JSONStore 将数据存储在本地设备中?
【发布时间】:2015-12-07 18:01:07
【问题描述】:

我正在使用 JavaScript 和 jquery 在 worklight 中进行登录页面,用户名和密码应该验证从 JSONstore 获取的数据?

如何在 worklight 中使用 JSONStore 在本地存储数据,以及如何在验证用户名和密码时从 JSONStore 获取数据?

在下面的代码中,我的数据将存储和获取,如果用户名和密码已输入验证:

var collections = {
          people : {
            searchFields : {name: 'string'}
          },
          orders : {
            searchFields: {name: 'string'}
          }
        };
            WL.JSONStore.init(collections)
            .then(function () {
          return WL.JSONStore.init(collections);
        })
            .then(function () {
          return WL.JSONStore.init(collections);
        })

        .then(function () {
            alert('Multiple inits worked');
        })
            .fail(function (err) {
         lert('Multiple inits failed' + err.toString());
        }); 

如何解决这个问题?

【问题讨论】:

  • 你的代码除了初始化一个集合之外什么也没做...
  • 对不起,初始化集合是什么意思?你能解释一下吗.. 我必须在哪里为 JSONStore 编码以及如何在 JSONStore 中为本地存储数据编码

标签: ibm-mobilefirst jsonstore


【解决方案1】:

您真的不应该在设备本地存储用户名和密码。这听起来不太安全……

另外,用户名和密码是从哪里来的?逻辑应该如何验证凭证?它需要将输入的内容与某些内容进行比较,以知道它是正确的。没有其他方法就无法实现,因此您需要提供此问题的答案...

同时,你可以看看下面的教程:Offline Authentication。

包含的示例应用程序假定您首先通过后端系统进行身份验证,然后允许在本地“离线”进行身份验证,以防 Internet 连接不可用。为此,它使用 JSONStore 来安全地进行身份验证。

本教程包含一个完整的实施示例,请务必遵循它,并在您的问题中提供缺失的信息。

本教程介绍如何使用 JSONStore API,包括 Add 方法:https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/data/jsonstore/jsonstore-javascript-api/

var collectionName = 'people';
var options = {};

var data = {name: 'yoel', age: 23};

WL.JSONStore.get(collectionName).add(data, options).then(function () {
 // handle success
}).fail(function (error) {
 // handle failure
});

【讨论】:

  • 仅关于如何在本地使用 JSONStore 存储数据?
  • 如果要将数据添加到 JSONStore 集合中,请使用添加 API。参考 JSONStore 教程:developer.ibm.com/mobilefirstplatform/documentation/…
  • 在上面的代码中,“人”是什么以及如何获取数据,var data = {name: 'yoel', age: 23};这是什么?
  • 这是一个名为 people 的集合,其中包含示例字段?
  • 请您解释一下代码,数据存储在哪里以及如何获取??
猜你喜欢
  • 2015-06-07
  • 2014-05-03
  • 1970-01-01
  • 2013-08-17
  • 2013-01-22
  • 2021-06-01
  • 2018-06-19
  • 1970-01-01
  • 2014-11-17
相关资源
最近更新 更多