Sencha Touch + Phonegap 应用程序的数据库
Database for Sencha Touch + Phonegap Application
您好,目前我在我的应用程序中的 Sencha Touch + Phonegap 中使用 LocalStorage,并从 WCF Rest 加载了超过 4000 条记录。在开发模式下我没有问题 运行 它在 Google Chrome 但是当我打包它并安装在 iOS8 设备时我的应用程序崩溃了。
以下是控制台中 localStorage 的总长度:
>JSON.stringify(localStorage).length
> 2917665
型号:
Ext.define("QualityAudit.model.DefectMatrix", {
extend: "Ext.data.Model",
config: {
identifier: { type: 'uuid', isUnique: true },
fields: [
{ name: "DefectMatrixID", type: "integer" },
{ name: "CustomerID", type: "integer" },
{ name: "CustomerName", type: "string" },
{ name: "DefectType", type: "integer" },
{ name: "DefectTypeName", type: "string" },
{ name: "Reference", type: "string" },
{ name: "Section", type: "string" },
{ name: "DefectDescription", type: "string" },
{ name: "SeverityID", type: "integer" },
{ name: "SeverityName", type: "string" },
{ name: "IsActive", type: "bool" },
{ name: "CreatedBy", type: "string" },
{ name: "CreatedDate", type: 'date', dateFormat: 'MS' }
]
}
});
店铺:
defectSync: function (counter, totRecords, callback) {
var me = this;
if (counter == undefined)
counter = 0;
//load defect matrix local local storage
var defectsLocalStore = Ext.getStore('DefectMatrix');
defectsLocalStore.load();
var defectssurl = window.REST_DMGetListAllPaging + counter;
QualityAudit.util.Proxy.doAjaxCall(defectssurl, '',
function (response) {
var data = Ext.JSON.decode(response.responseText); //encode Json List
defectsLocalStore.load({
callback: function (records, operation, success) {
Ext.Array.each(data, function (record) {
counter++;
record.dirty = true;
defectsLocalStore.add(record);
defectsLocalStore.sync();
});
console.log('DECFECT DATA AFTER SYNC: ' + defectsLocalStore.getData().length);
//Check if all records loaded on local storage is equail to total defect rows then complete
if (defectsLocalStore.getData().length >= totRecords) {
console.log('defect loading successfull');
callback();
} else {
//Trigger again until condition is met
me.defectSync(counter, totRecords, callback);
}
},
scope: this
});
},
function (response) {
defectsLocalStore.load();
callback(0);
});
}
有人在您的项目中尝试过使用 webSQL 或 SQLlite 吗?我找不到任何好的样本。
非常感谢任何帮助和建议。
我几乎在每个项目中都使用 SQLite。恕我直言,最好的插件是 Cordova/PhoneGap SQLitePlugin.
你在页面上找到了一些示例,如何使用插件以及如何在 cordova 中使用 SQLite。
您可以将存储与代理一起使用:'sql',它将使用 WebSQL 创建本地数据库。
sql proxy Doc
您好,目前我在我的应用程序中的 Sencha Touch + Phonegap 中使用 LocalStorage,并从 WCF Rest 加载了超过 4000 条记录。在开发模式下我没有问题 运行 它在 Google Chrome 但是当我打包它并安装在 iOS8 设备时我的应用程序崩溃了。
以下是控制台中 localStorage 的总长度:
>JSON.stringify(localStorage).length
> 2917665
型号:
Ext.define("QualityAudit.model.DefectMatrix", {
extend: "Ext.data.Model",
config: {
identifier: { type: 'uuid', isUnique: true },
fields: [
{ name: "DefectMatrixID", type: "integer" },
{ name: "CustomerID", type: "integer" },
{ name: "CustomerName", type: "string" },
{ name: "DefectType", type: "integer" },
{ name: "DefectTypeName", type: "string" },
{ name: "Reference", type: "string" },
{ name: "Section", type: "string" },
{ name: "DefectDescription", type: "string" },
{ name: "SeverityID", type: "integer" },
{ name: "SeverityName", type: "string" },
{ name: "IsActive", type: "bool" },
{ name: "CreatedBy", type: "string" },
{ name: "CreatedDate", type: 'date', dateFormat: 'MS' }
]
}
});
店铺:
defectSync: function (counter, totRecords, callback) {
var me = this;
if (counter == undefined)
counter = 0;
//load defect matrix local local storage
var defectsLocalStore = Ext.getStore('DefectMatrix');
defectsLocalStore.load();
var defectssurl = window.REST_DMGetListAllPaging + counter;
QualityAudit.util.Proxy.doAjaxCall(defectssurl, '',
function (response) {
var data = Ext.JSON.decode(response.responseText); //encode Json List
defectsLocalStore.load({
callback: function (records, operation, success) {
Ext.Array.each(data, function (record) {
counter++;
record.dirty = true;
defectsLocalStore.add(record);
defectsLocalStore.sync();
});
console.log('DECFECT DATA AFTER SYNC: ' + defectsLocalStore.getData().length);
//Check if all records loaded on local storage is equail to total defect rows then complete
if (defectsLocalStore.getData().length >= totRecords) {
console.log('defect loading successfull');
callback();
} else {
//Trigger again until condition is met
me.defectSync(counter, totRecords, callback);
}
},
scope: this
});
},
function (response) {
defectsLocalStore.load();
callback(0);
});
}
有人在您的项目中尝试过使用 webSQL 或 SQLlite 吗?我找不到任何好的样本。
非常感谢任何帮助和建议。
我几乎在每个项目中都使用 SQLite。恕我直言,最好的插件是 Cordova/PhoneGap SQLitePlugin.
你在页面上找到了一些示例,如何使用插件以及如何在 cordova 中使用 SQLite。
您可以将存储与代理一起使用:'sql',它将使用 WebSQL 创建本地数据库。 sql proxy Doc