PDA

View Full Version : ExtJS JsonWriter undefined parameters



mcamer
19 Jul 2010, 7:29 AM
So I'm a newbie for ExtJS and trying to do some integration with microsoft's OData services.

I basically extended a JsonReader that would read the "oddly formatted" JSON that the OData service is returning, I'm creating records in the reader and returning it in readRecords().... By doing that, I was able to see the data coming from the service in my Grid, so far so good!

Now the writing back was a bit of an issue, I assumed that by putting in a JsonWriter to the store, that it will magically compose the JSON string as a post action to the service. But for some reason I was checking the post parameters via firebug, and it was something like this

undefined {}

The URL is exactly what I defined, so it's acting as expected, but it's not gathering the values and composing the JSON parameters!

The JSON Writer I defined is as follow


var writer = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});
I guess my question would be, would it be possible I screwed up something with extending the JsonReader? Or are they not related? And what would cause such a behavior?

If my question is too vague, I would love to debug this myself, but I guess I would like to know where to start from? What would be the function that composes the parameters for JSON Requests in the JsonWriter?

Thank you in advance!


-----
I was actually just debugging this, and I noticed that during the Ajax request composing, it's treating the update as a creation! I found out that for some reason the records phantom property is set to true, therefore it's trying to make a create request rather than an update one. Does that ring a bell?

hjones
2 Aug 2010, 7:29 PM
Make sure you have the idProperty config property on your reader/store.
If you don't sent this up then the record will auto assign an id and set phantom = true.
Here's a comment from Ext.data.Record.js...

Any record which has a real database pk set as its id property
* is NOT a phantom -- it's real.

Also, if you are using the mapping config property in the field definition then idProperty should be pointing to that...in my case 'ID' instead of the default 'id'.

I struggled with this for an hour or two this afternoon before figuring it all out.


So I'm a newbie for ExtJS and trying to do some integration with microsoft's OData services.

I basically extended a JsonReader that would read the "oddly formatted" JSON that the OData service is returning, I'm creating records in the reader and returning it in readRecords().... By doing that, I was able to see the data coming from the service in my Grid, so far so good!

Now the writing back was a bit of an issue, I assumed that by putting in a JsonWriter to the store, that it will magically compose the JSON string as a post action to the service. But for some reason I was checking the post parameters via firebug, and it was something like this

undefined {}

The URL is exactly what I defined, so it's acting as expected, but it's not gathering the values and composing the JSON parameters!

The JSON Writer I defined is as follow


var writer = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});
I guess my question would be, would it be possible I screwed up something with extending the JsonReader? Or are they not related? And what would cause such a behavior?

If my question is too vague, I would love to debug this myself, but I guess I would like to know where to start from? What would be the function that composes the parameters for JSON Requests in the JsonWriter?

Thank you in advance!


-----
I was actually just debugging this, and I noticed that during the Ajax request composing, it's treating the update as a creation! I found out that for some reason the records phantom property is set to true, therefore it's trying to make a create request rather than an update one. Does that ring a bell?