gpt4 book ai didi

javascript - Sencha Touch - 重新加载/刷新应用程序后商店清空

转载 作者:行者123 更新时间:2023-11-28 01:15:00 25 4
gpt4 key购买 nike

我正在努力寻找将数据保存到本地存储的方法,但现在我这边似乎运气不佳。我可以成功添加/删除商店中的商品,但是,每当我尝试刷新或重新加载页面(谷歌浏览器)时,商店中似乎找不到数据。

这是我的代码:

模型: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'
}

});

Controller :

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;
}
});
}
}

最佳答案

添加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'
}
}

关于javascript - Sencha Touch - 重新加载/刷新应用程序后商店清空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23948683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com