PDA

View Full Version : EditableGrid extraParams - dynamic



chrislarsen3
24 Jul 2013, 7:17 AM
I have done a lot of research relating to couchdb interaction, and although I've made a lot of progress I'm still stuck on the PUT part and hoping someone can help.

I have an editable grid that does an auto-sync, so i don't have any button code at all. I simply want to pass the _rev parameter dynamically based on the record I'm trying to update.. it passes just fine when i set it to an arbitrary value, but I am struggling to have it populate with the _rev of the actual document i'm updating. I do have _rev in my model accessible to me but I don't understand how to grab it for the extraParams directive.. here is my code for the model, hoping someone can help. :((


Ext.define('MyApp.model.Stocks', {
extend: 'Ext.data.Model',
alias: 'model.Stocks',

idProperty: '_id',

fields: [
{
name: 'company',
mapping: 'company'
},
{
name: 'price',
mapping: 'price'
},
{
name: 'change',
mapping: 'change'
},
{
name: 'pctChange',
mapping: 'pctChange'
},
{
name: 'lastChange',
mapping: 'lastChange'
},
{
name: '_id',
mapping: '_id'
},
{
name: '_rev',
mapping: '_rev'
}
],

proxy: {
type: 'rest',
api: {
create: 'http://localhost/stocks',
read: 'http://localhost/stocks/_design/views/_view/stockview?include_docs=true',
update: 'http://localhost/stocks',
destroy: 'http://localhost/stocks'
},
extraParams: {
_rev: 1
},
url: 'http://localhost',
writer: {
type: 'json',
nameProperty: 'mapping'
},
reader: {
type: 'json',
idProperty: '_id',
root: 'rows',
successProperty: 'ok',
totalProperty: 'total_rows',
record: 'doc'
}
}
});

slemmon
25 Jul 2013, 9:42 PM
You can listen to the store's beforesync event and pass extraparams then as needed:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Store-event-beforesync