简体   繁体   English

使用 OpenUI5 和 Apache Cordova 的本地存储

[英]Local storage using OpenUI5 and Apache Cordova

I'm building a mobile app using OpenUI5 and Cordova.我正在使用 OpenUI5 和 Cordova 构建一个移动应用程序。 This app consume OData services but must support full offline capabilities.此应用程序使用 OData 服务,但必须支持完整的离线功能。 There are many optiones to store data using Cordova such as LocalStorage, Web SQL or even FileWriter.有很多选项可以使用 Cordova 存储数据,例如 LocalStorage、Web SQL 甚至 FileWriter。 Also I find that OpenUI5 framework offer jQuery.sap.storage to store data through LocalStorage but I can't take this option into account due to the limited storage capacity (5MB).此外,我发现 OpenUI5 框架提供 jQuery.sap.storage 以通过 LocalStorage 存储数据,但由于存储容量 (5MB) 有限,​​我无法考虑此选项。

Is it possible to request the entire data model from the OData service and convert it into JSON model?是否可以从 OData 服务请求整个数据模型并将其转换为 JSON 模型? Because if there is any way to accomplish this, I could write files for every entity in the model (and the metadata file) using the FileWriter and consume this model when the app goes offline.因为如果有任何方法可以实现这一点,我可以使用 FileWriter 为模型中的每个实体(和元数据文件)编写文件,并在应用程序离线时使用该模型。

Does anyone tried to do something like this?有没有人试图做这样的事情?

Edited已编辑

Thanks for answering...谢谢回答...

I'm using jumpifzero tips to set data from the OData services into the Json model, like this:我正在使用 jumpifzero 技巧将来自 OData 服务的数据设置到 Json 模型中,如下所示:

    var sServiceUrl = "http://address:port/DataService.svc/";       
    var odataModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
    var jsonModel = new sap.ui.model.json.JSONModel();

    odataModel.read("/Dates", {
        async: false,
        success: function (odata, response) {
            jsonModel.setData({ Dates: odata.results });
        }
    });

    this.setModel(jsonModel);

You can also read the odata for each entityset, with the .read method, without any filter.您还可以使用 .read 方法读取每个实体集的 odata,无需任何过滤器。 In the success function given to the read, you can put the JS objects in a JSON model.在提供给读取的成功函数中,您可以将 JS 对象放入 JSON 模型中。 You can make a layer that fills the JSON model from the odata when online and from localstorage when offline.您可以创建一个层,在线时从 odata 和离线时从 localstorage 填充 JSON 模型。

You have an option to create offline apps (CRUD) using offline Kapsel plugin (Cordova plugin developed by SAP) that comes with SAP Mobile Platform.您可以选择使用 SAP Mobile Platform 附带的离线 Kapsel 插件(由 SAP 开发的 Cordova 插件)创建离线应用程序 (CRUD)。 You should buy license for SAP Mobile Platform.您应该购买 SAP Mobile Platform 的许可证。 You can find more information here: http://scn.sap.com/docs/DOC-58063您可以在此处找到更多信息: http : //scn.sap.com/docs/DOC-58063

I don't suggest offline Kapsel plugin.我不建议离线 Kapsel 插件。 It is not mature enough to use it and it is actually under development.使用起来还不够成熟,实际上还在开发中。 Furthermore you would need an SMP server for offline feature.此外,您需要一个 SMP 服务器来实现离线功能。 I would rather say you should use a half-baked solution that you form according your needs eg: http://coenraets.org/blog/2012/05/simple-offline-data-synchronization-for-mobile-web-and-phonegap-applications/我宁愿说您应该使用根据您的需要形成的半生不熟的解决方案,例如: http : //coenraets.org/blog/2012/05/simple-offline-data-synchronization-for-mobile-web-and- phonegap-应用程序/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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