我正在努力寻找如何将数据保存到本地存储的方法,但现在似乎没有运气。我可以在商店中成功添加/删除商品,但每当我尝试刷新或重新加载页面时(谷歌浏览器)看起来都没有在商店中找到数据。
这是我的代码:
型号:Pendingmodel.js
Ext.define('mysample.model.PendingModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'ALIAS'
},
{
name: 'OBJECT'
},
{
name: 'DATETIME'
},
{
name: 'FIELDVALUE'
}
],
proxy: {
type: 'localstorage',
id: 'PendingModelProxy'
}
}
});
商店:Pendingstore.js
Ext.define('mysample.store.PendingStore', {
extend: 'Ext.data.Store',
requires: [
'mysample.model.PendingModel'
],
config: {
autoLoad: true,
model: 'mysample.model.PendingModel',
storeId: 'PendingStore'
}
});
控制器:
onDraftCommand: function (form, isTapped) {
var isValid = true;
var me = this, getForm = me.getLeadsView();
var pendingItems = getForm.getValues();
var cleanItems = getForm.getValues();
cleanItems['reset'] = function() {
for (var prop in this) {
delete this['reset'];
delete this['eventParameter'];
this[prop] = '';
}
}
if(isTapped == true && isValid == true) {
Ext.Msg.confirm('Message', 'Are you sure you want to save this on draft?', function (btn) {
switch (btn) {
case 'yes':
var date = new Date(), id = date.getUTCMilliseconds();
var obj = {
'ALIAS': 'leadsview',
'OBJECT': 'Leads Form',
'id': id,
'DATETIME': date,
'FIELDVALUE': pendingItems,
};
console.log('Leads pending store');
console.log(obj);
Ext.data.StoreManager.lookup('PendingStore').add(obj);
Ext.data.StoreManager.lookup('PendingStore').sync();
console.log(Ext.data.StoreManager.lookup('PendingStore'));
//clear form
cleanItems.reset();
getForm.setValues(cleanItems);
//Ext.getCmp('signatureField').removeImage();
break;
default:
break;
}
});
}
}
答案 0 :(得分:1)
在模型中添加identifier strategy,如下所示。
Ext.define('mysample.model.PendingModel', {
extend: 'Ext.data.Model',
config: {
identifier: 'uuid', // add this
fields: [
{
name: 'id',
type: 'int'
}
],
proxy: {
type: 'localstorage',
id: 'PendingModelProxy'
}
}
答案 1 :(得分:0)
您需要在模型中添加唯一标识符,如下所示: -
Ext.define('mysample.model.PendingModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.identifier.Uuid'
],
config: {
identifier: {
type: 'uuid',
isUnique: true
},
fields: [
{
name: 'id',
type: 'int'
},
{
name: 'ALIAS'
},
{
name: 'OBJECT'
},
{
name: 'DATETIME'
},
{
name: 'FIELDVALUE'
}
],
proxy: {
type: 'localstorage',
id: 'PendingModelProxy'
}
}
});