PDA

View Full Version : DataWriter & REST Help



kouphax
11 Jun 2009, 6:46 AM
I have updated this post to reflect my current progress. I am trying to implement a RESTful store but I am having difficulties. I can't seem to get any Update or Delete events to fire. The code below attempts to remove everything from the store but the JSONWriter doesn't propagate this back to the server for some reason (I have tried removeAt, removeAll, destroyRecord) but I can't seem to get the API to work.

Furthermore when I create a record the back end assigns it a new auto ID but even though I return the result data= [modified record] this doesn't get reflected on the front end - nor does my write event fire. Can anyone help me with what I am doing wrong?


Ext.onReady(function(){

new Ext.Button({
renderTo: "bd",
text: 'Kill All',
scale:"large",
handler:function(){
store.removeAll();
store.save();
}
});

// Create a standard HttpProxy instance.
var proxy = new Ext.data.HttpProxy({
url:'TeaMatrix/Users'
});

// Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
var reader = new Ext.data.JsonReader({
root:"data"
}, [
{name: 'UserProfileID', type: 'int'} ,
{name: 'Name', allowBlank: false}
]);

// The new DataWriter component.
var writer = new Ext.data.JsonWriter();

// Typical Store collecting the Proxy, Reader and Writer together.
var store = new Ext.data.Store({
id: 'user',
autoLoad:true,
restful: true, // <-- This Store is RESTful
proxy: proxy,
reader: reader,
writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
listeners: {
write : function(store, action, result, response, rs) {
debugger;
}
}
});