PDA

View Full Version : problems with adding to store->proxy



dkjærgaard
2 Mar 2011, 5:04 AM
Hi,

I just started using extjs so excuse me for missing knowledge. I'll start with the code:


var user_rec = Ext.data.Record.create({name: 'brugernavn', name: 'password', name: 'readonly', name: 'brugerid'});

var writer = new Ext.data.JsonWriter({
encode: true,
writeAllFields: true
});

var proxy = new Ext.data.HttpProxy({
api: {
read: 'get-users.php',
create: 'add-user.php',
update: 'change-user.php',
destroy: 'remove-user.php'
}
});

var store = new Ext.data.JsonStore({
fields: ['brugernavn','password','readonly','brugerid'],
proxy : proxy,
writer: writer,
autoLoad : true,
autoSave: true
});

var add_user = function(btn) {
store.add(new user_rec(new_form.getForm().getValues()));
}

var new_form = new Ext.form.FormPanel({
xtype:'form',
labelWidth:110,
frame:true,
items:[{
xtype:'textfield',
fieldLabel:'Brugernavn',
name: 'brugernavn'
},{
xtype:'checkbox',
fieldLabel:'Readonly',
name: 'readonly'
},{
// textfield
fieldLabel:'Password',
xtype:'textfield',
name: 'password'
}]
});

var win_new = new Ext.Window({
title:'Tilføj bruger',
renderTo:Ext.getBody(),
width:420,
height:240,
border:false,
layout:'fit',
modal: true,
items: new_form,
closeAction: 'hide',
buttons : [
{
text : 'OK',
handler : add_user
}
]
});



When i add an user with this code, the store is updated, and the proxy i called, however i dont get any useable params. I get and undefined {}, but how can i get the json, stored in the record just added, back to the add-user.php script.

Thanks alot for any help or pointers.

-D Kjærgaard

mankz
2 Mar 2011, 5:48 AM
The JsonWriter isn't super intuitive, it needs your reader to have a 'root' config property.

Try something like:



var store = new Ext.data.JsonStore({
fields: ['brugernavn','password','readonly','brugerid'],
proxy : proxy,
root : 'foo',
writer: writer,
autoLoad : true,
autoSave: true
});

dkjærgaard
2 Mar 2011, 5:56 AM
Hi Mark,

Ah ok, so now i know where the undefined came from. My problem is that there is not data in the json sent. My post params is now foo {}, i would expect something like foo {brugernavn:row_add.brugernavn, password .....}.