gpt4 book ai didi

javascript - Sencha touch2,本地存储中的数据未进入本地存储

转载 作者:行者123 更新时间:2023-11-30 12:59:16 25 4
gpt4 key购买 nike

型号:

Ext.define('SkSe.model.PlacesLocal',{
extend:'Ext.data.Model',
config:{
fields:['id', 'name','icon','required_stamps', 'active_stamps','description', 'campaign_id', 'user_favorites' , 'live_action_number'],
proxy: {
type: 'localstorage',
id : 'local-places-id'

}

}

});

商店:

Ext.define('SkSe.store.PlacesLocal', {
extend:'Ext.data.Store',
config: {
storeId: 'PlacesLocal',
model: "SkSe.model.PlacesLocal",
sorters: 'name',
grouper: {
groupFn: function (item) {
return item.get('name')[0];
}
},
groupDir: 'DESC'


}
});

离线 - 在线商店同步:

Ext.define('SkSe.store.Places',{
extend:'Ext.data.Store',

config:{

autoLoad:true,
autoSync:true,
model:'SkSe.model.Places',
sorters: 'name',
grouper: {
groupFn: function (item) {
return item.get('name')[0];
}
},
groupDir: 'DESC',
proxy:{
type:'ajax',
url:'http://localhost/campaigns/',
reader:{
type:'json',
//name of array where the results are stored
rootProperty:'results'
}
},

listeners: {
load: function() {

var PlacesLocal = Ext.data.StoreManager.lookup('PlacesLocal');
// Clear proxy from offline store

if (navigator.onLine) {
console.log("Hm");

// Loop through records and fill the offline store
this.each(function(record) {

PlacesLocal.add(record.data);

});

// Sync the offline store
PlacesLocal.sync();
}
}

}
}
});

显然 placesLocalstore 确实获取了数据,但由于某种原因它没有存储在 localstorage 中。

关键的 local-places-id 出现在 localstorage 中但没有任何数据。

最佳答案

我认为问题在于当您这样做时:

PlacesLocal.add(record.data);

record.data 中有一个id 字段,其值。因此,该记录不会被视为新记录。也不会被认为是修改了,因为它没有被修改,它也不会被认为是被删除了(解释留给读者作为练习)。

换句话说,对于商店来说,没有什么可以同步的。任务完成。

这是 getNewRecords 的代码,用在 sync 方法中:

function() {
return this.data.filterBy(function(item) {
// only want phantom records that are valid
return item.phantom === true && item.isValid();
}).items;
}

我想你现在已经猜到你需要做什么了,但让我多说几句:

var recordsData = store.getRange().map(function(record) { return record.data }),
newRecords = PlacesLocal.add(recordsData);

Ext.each(newRecords, function(record) {
record.phantom = true;
});

// Now it should have plenty of work!
PlacesLocal.sync();

关于javascript - Sencha touch2,本地存储中的数据未进入本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17857309/

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