PDA

View Full Version : Insert records in store and sync it with localstorage



couetbis
1 Apr 2011, 4:45 AM
Hi,
I'm not sure that it's bug.
My problematic : I inserts new records in a store and sync it with localstorage (online/offline simulation).

My code :


app.stores.tourneesOnLine = new Ext.data.JsonStore({
model : 'app.models.Tournee',
. . .
listeners :{
load : function(thiss, records, succes){
console.log("I think we are online");
app.stores.tournees.insert(0,records);
app.stores.tournees.sync(); // not good in localstorage
this.each(function (tournee) {
var storeMission = tournee.missions();
storeMission.sync(); //good in localstorage
. . .
}
}
}
. . .
});

In touch 1.0, stores are all save in localstorage but in touch 1.1 first store isn't save.

In sencha-touch.js, I comments "this.dirty = false;" in Model constructor :


Ext.data.Model = Ext.extend(Ext.util.Stateful, {
. . .

constructor: function(data, id) {
data = data || {};

this.internalId = (id || id === 0) ? id : Ext.data.Model.id(this);

Ext.data.Model.superclass.constructor.apply(this);

//add default field values if present
var fields = this.fields.items,
length = fields.length,
field, name, i;

for (i = 0; i < length; i++) {
field = fields[i];
name = field.name;

if (data[name] == undefined) {
data[name] = field.defaultValue;
}
}

this.set(data);
//this.dirty = false;

if (this.getId()) {
this.phantom = false;
}

if (typeof this.init == 'function') {
this.init();
}
},
. . .


It's now good, but it's a mistake.
Thanks for your advice.