PDA

View Full Version : ExtJS Store - CRUD



tomearly
22 Aug 2011, 2:51 AM
Hi,

I'm using Ext Scheduler and can add events to the UI, and these seem to be added to the store (according to FireBug)

When I try and sync the store, nothing gets posted for the create call (i.e. the new records) or the update call, apart from the _dc param.

Here is the store code below, if you need more of the code let me know.

Thanks,


eventStore : Ext.create("Ext.data.Store", {
idProperty : 'id',
model : 'Sch.model.Event2',
restful:true,
autoLoad: true,
proxy: {
type: 'ajax',
api: {
create: 'myBackend.php?action=create', // Called when saving new records
read: '/cgi-bin/EV_Rostering_Events_Get.pl?branch=' + branch + '&view=' + view,
update: 'myBackend.php?action=update', // Called when updating existing records
destroy: 'myBackend.php?action=destroy' // Called when deleting existing records
},
reader: {
type: 'json'
},
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
}),
timeout: 10000
},
listeners: {
//add
add: function(store, records, index, options)
{
console.log(records);
},
update: function(store, records, index, options)
{
console.log('update event');
}
//remove
//update
}
})

tomearly
22 Aug 2011, 4:08 AM
I have found out why nothing was being posted.

Within my JsonWriter definition I needed to add root: 'data', this seems to post data now.


writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: false,
root: 'data'
})

However, it seems to post all the data in my store each time, not just the updated or newly created stuff?

skirtle
22 Aug 2011, 7:33 PM
Try putting a breakpoint in your code where you do the sync, then step into the method. It looks like that bit of the ExtJS code is quite straightforward so it shouldn't be too hard to establish why its grabbing the wrong records.

Hopefully that'll give you enough to solve the problem. If not, let us know what you find.

tomearly
23 Aug 2011, 2:41 AM
Hi Skirtle,

I've added it a break point and it seems that the getNewRecords() method seems to be returning all records.

I've dumped the records to the console and can see that the records in initially in the store are phantom records.

The record seems to have an ID though, so i'm a bit puzzled.

Here is an excerpt from the FireBug console.

$className"Sch.model.Event2"
$inheritableStatics["setProxy", "getProxy", "load"]
alternateClassName"Ext.data.Record"
associationsObject { items=[0], map={...}, keys=[0], more...}
configObject {}
dataObject { Id="3", ResourceId="RPTEST", StartDate=Date, more...}
defaultProxyType"ajax"
dirtyfalse
editingfalse
eventOptionsReRegExp
eventedfalse
eventsObject {}
fieldsObject { items=[10], map={...}, keys=[10], more...}
id"Sch.model.Event2-ext-record-24"
idProperty"id"
index0
internalId"ext-record-24"
isModeltrue
isObservabletrue
mixinsObject { observable={...}}
modelName"Sch.model.Event2"
modifiedObject {}
persistenceProperty"data"
phantomtrue

skirtle
23 Aug 2011, 2:53 AM
Is it just that your id field has a capital I rather than a lowercase i in your data?

tomearly
23 Aug 2011, 3:28 AM
Hi Skirtle,

Yes, your right. I have changed the Id field in my data to be id instead and sync works exactly as it should!

Many Thanks,

Tom