mardi 20 mai 2014

store json array and sync to localstorage

Hi i am new for sencha touch. I need to sync online data to offline localstorage. Please see my json result.The json result is store in hierarchy format and getting from server

Json result



Code:



items": [ "loyaltyMasterId": "6",
"loyaltyCardId": "23",
"totalPoint": "0.00",
"lastVisited": "2013-10-23 13:35:17.062",
"pushNotification": "Y",
"blueDisplay": "Y",
"loyaltyCardName": "Jusco",
"headerCss1": "",
"headerCss2": "",
"borderLcss": "",
"borderRcss": "",
"borderScss": "",
items": [
"loyaltyMasterId": "7",
"loyaltyCardId": "23",
"totalPoint": "0.00",
"lastVisited": "2013-10-23 13:35:17.062",
"pushNotification": "Y",
"blueDisplay": "Y",
"loyaltyCardName": "Jusco",
"headerCss1": "",
"headerCss2": "",
"borderLcss": "",
"borderRcss": "",
"borderScss": "",

]
],

ModelOffline js


Code:



Ext.define('blackbutton.model.Blue.BlueList_Off9', { //Oyster create 17-Sept-2013 for store localstorage extend: 'Ext.data.Model',
requires: ['Ext.ux.Global.GlobalVariable'],
config: {
idProperty: 'loyaltyMasterId',
identifier: 'uuid',
fields: [
{ name: 'loyaltyMasterId' },
{ name: 'loyaltyCardId' },
{ name: 'totalPoint' },
{ name: 'lastVisited' },
{ name: 'loyaltyCardName' },
{ name: 'headerCss1' },
{ name: 'headerCss2' },
{ name: 'borderLcss' },
{ name: 'borderRcss' },
{ name: 'borderScss' },
{ name: 'headerImage1' },
{ name: 'headerImage2' },
{ name: 'contentImage1' },
{ name: 'contentImage2' },
{ name: 'bottomImage1' },
{ name: 'bottomImage2' },
{ name: 'bodyCss1' },
{ name: 'bodyCss2' },
{ name: 'contentCss1' },
{ name: 'contentCss2' },
{ name: 'bottomCss1' },
{ name: 'bottomCss2' },
{ name: 'designType' },
{ name: 'couponType' },
{ name: 'pushNotification', type: 'string' },
{ name: 'blueDisplay', type: 'string' },
{ name: 'result',type: 'string' },
{ name: 'sessionId' },
{ name: 'deviceId' },
{ name: 'SN' }
],


proxy: {
type: 'localstorage',
id : 'blueListoff9',
noCache: false, // get rid of the '_dc' url parameter

extraParams: {
sessionId: "1",
},
}
}
});

StoreOffline


Code:



Ext.define('blackbutton.store.Blue.BlueList_Off9', { //extend: 'Ext.data.TreeStore',
extend: 'Ext.data.Store',
requires: [
'blackbutton.model.Blue.BlueList'
],
config: {
//defaultRootProperty: 'items',
model: 'blackbutton.model.Blue.BlueList_Off9',
storeId : 'blueListStore_Off9',
autoLoad: true,
clearOnPageLoad: true,



}
});



How i store to localstorage


Code:



markerStore.getProxy().setTimeout(120000); markerStore.load(function(records, operation, successful) {

if(successful) {
var responseText = operation.getResponse().responseText;
var objresponseText = JSON.stringify(responseText);
markerStoreLocalStorage.add(objresponseText);
markerStoreLocalStorage.sync();
markerStoreLocalStorage.load();


//

}
});

console.of objresponseText


Code:



"{\"items\":[{\"loyaltyMasterId\":\"6\",\"loyaltyCardId\":\"23\",\"totalPoint\":\"0.00\",\"lastVisited\":\"2013-10-23 13:35:17.062\",\"pushNotification\":\"Y\",\"blueDisplay\":\"Y\",\"loyaltyCardName\":\"Jusco\",\"headerCss1\":\"\",\"headerCss2\":\"\",\"borderLcss\":\"\",\"borderRcss\":\"\",\"borderScss\":\"\",\"headerImage1\":\"iVBORw0KGgoAAAANSUhEUgAAADAAAAAXCAYAAABNq8wJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\\r\\nAAALEgAACxIB0t1+\\/AAAAMJ0RVh0U29mdHdhcmUAVGhpcyBkb2N1bWVudCBjb250YWlucyBubyB ....




My loclstorage is getting empty. Any solution? Thanks


Aucun commentaire:

Enregistrer un commentaire