PDA

View Full Version : JsonWriter Issue



golly
8 Dec 2011, 8:24 AM
Hi guys. I vahe a problem with the JSON Writer. I'm using an ASP.NET server. I want to create a record and put it in a store. This part is working very well. But the create method of the api is putting the record in parameters. Is there any way to have it in one single json param? Here is my code:


this.server = "http://localhost:3361/Backend/Proxy.aspx";

Ext.define('example', {
extend: 'Ext.data.Model',
fields: [{name : "ID"},
{name: "description"},
{name: "datetime"},
{name: "activ"},
{name: "employee"},
{name: "place"}]
});
this.baum = new Ext.data.Store({
id:'baum',
model:'example',
autoSync:true,
proxy(
{
headers:{"Content-type":"application/json"},
type:'jsonp',
api:{
create:this.server+'/Appointment/Create',
read:this.server+'/Appointment/Read',
update:this.server+'/Appointment/Update',
destroy:this.server+'/Appointment/Destroy'
},
reader: {
type: 'json',
idProperty:"ID",
totalProperty:"d.results",
successProperty:"d.success",
messageProperty:"d.message",
root:"data"
},
writer: {
type: "json",
writeAllFields: false,
root: "data"
},
},

sortInfo:{field:"datetime",direction:"ASC"},
});
var store = Ext.StoreMgr.lookup('baum');

//Using this in insert****************************
var record = new example({
ID:"77",
description: "someTitle",
datetime: "12-12-1212",
employee: "someEmployee",
place: "home"
});

//Or this... its the same thing***********************
store.insert(0,{
ID:"77",
description: "someTitle",
datetime: "12-12-1212",
employee: "someEmployee",
place: "home"
});


The Network activity simply show the create:
- http://localhost:3361/Backend/Proxy.aspx/Appointment/Create?_dc=1323360958401&records=ID=77&description=someTitle&datetime=12-12-1212&employee=someEmployee&place=home&activ=&callback=Ext.data.JsonP.callback2

But i need it like the root in the writer (In one JSON Param):
- http://localhost:3361/Backend/Proxy.aspx/Appointment/Create?_dc=1323360958401&data=HTML ENCODED JSON STRING&callback=Ext.data.JsonP.callback2

In ExtJS 3.4 a good friend of mine used the ScripttagProxy and the JSON Param generated automatically.

Can anyone help me with this problem?


PS.: The JSON Writer example didn't help

tobiu
8 Dec 2011, 9:58 AM
the script tag proxy exists in ext 4 as well:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.JsonP

you can also manually create an extension to wrap the params into a json string. i even think there are examples for it in the forums.

golly
9 Dec 2011, 12:30 AM
The JsonP Proxy is not working either.

Anyone knows hor to configure it, so that the all records are in one json param?

infrared
19 Jul 2013, 6:18 AM
writer:
{
type: 'json',
writeAllFields: false,
root: 'data',
encode: true // A MUST, OTHERWISE INSERT and UPDATE do not send to server as array
}