PDA

View Full Version : Model Field Persist config not working for me?!



parky128
8 Oct 2013, 5:56 AM
Hi,

I have a couple of fields on a model that do not need to be persisted with the server, but need their values maintained between store load operations. I see the 'persist' config option on the model config in the docs.

But when I have tried using this, the values I set prior to a secondary load option on my store get overwritten (set back to their defaults).

Here is my model code:


Ext.define('PinpointersTouch.model.CurrentLocation', {
extend: 'Ext.data.Model',

config: {
fields: [
{
name: 'UntID'
},
{
name: 'UnitName'
},
{
name: 'Lat'
},
{
name: 'Lon'
},
{
name: 'InJourney'
},
{
name: 'Location'
},
{
allowNull: false,
dateFormat: 'Y-m-d\\TH:i:s',
name: 'EventDT',
type: 'date'
},
{
name: 'UrrID'
},
{
name: 'MapIcon'
},
{
name: 'EventDTDisplay'
},
{
name: 'Subtitle'
},
{
defaultValue: false,
name: 'IsSelected',
persist: false,
type: 'boolean'
},
{
name: 'Marker',
persist: false
}
]
}
});

The two fields at the end are the ones in question, these are definitely not being returned by the server so its not something silly like that causing the values to be overwritten.

In the case of the Marker field, this I use for storing a Google Maps marker object, and I simply do the following on my model instance:


r.set('Marker',unitMarker);

I know this works for initially setting the value of Marker, as I use these for other places in the code prior to any further store load operations.

So what could be causing this problem for me? have I misunderstood the use of this persist config option?

BTW - I am using ST 2.3 too.

Kurt001
8 Oct 2013, 8:51 AM
Are you using sync() or load()?
load() will reset all values. sync() should work fine.

Let me know if not and I will do some testing.

parky128
8 Oct 2013, 11:04 AM
Thanks for your reply, I am using load as follows:


Ext.getStore('CurrentLocationStore').load({
addRecords:true,
callback: function(records, operation, success) {
app.fireEvent('currentlocationsupdate',records);

Ext.Viewport.setMasked(false);
},
scope:this
});

I'm then picking up the records in an event listener elsewhere and there is where I find my persist-false fields are overwritten.

I have used the sync() call before on other applications but I thought this is only if you want to sync up creates, updates and deletes with the server. In this situation the store is for read only purposes only so I don't think I can use sync() here?

On another note, I would normally use the updaterecord event on the store, but when I use load(), after new records are retrieved and saved in the store, any records that get replaced don't fire the updaterecord event. But then I guess they would not since the record is being 'replaced' and not updated.

Kurt001
8 Oct 2013, 12:44 PM
But then, persist says it's exluded from sync.
I guess that you are using the same id and hence the add acutally overwrites the data, which makes sense.
So I guess you have to listen to updaterecord event of your store and look through your modified values. If the persist data are inside the modifiedValues you rewrite them (not sure if this leads to another updaterecord :( .