-
31 Jul 2010 1:12 AM #1
JsonReader, metaData: undefined root property on create action
JsonReader, metaData: undefined root property on create action
I'm trying to set up a store which holds a JsonReader defined dinamically using the metaData property of the JSON data, the store is:
the server response, on each calls, includes the metaData definition as of:Code:var gecalPdlFiltroStore = new Ext.data.Store({ id: 'gecalPdlFiltroStore', url: '/adon.pl', baseParams: {act: 'GECAL', Mode: 'PdlFiltro'}, autoLoad: false, autoSave: true, reader: new Ext.data.JsonReader(), writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: false }), listeners: { load: function(me, records, options) { }, exception: function(writer, type, action, options, response, arg) { var data = response; if (type== "response") { data = Ext.util.JSON.decode(response.responseText); } Ext.Msg.alert(translate('Attention'), data.msg, function() { this.reload(); }, this); }, write: function(me, action, result, res, rs) { if (!result[me.reader.successProperty]){ Ext.Msg.alert(translate('Attention'), result[me.reader.messageProperty], function() { this.reload(); }, me); } } } });
that's just an example to figure out what the reader gets for its metaData definition.Code:{"msg":"","success":true,"metaData":{"messageProperty":"msg","totalProperty":"totalCounts","fields":[{"name":"ID","type":"int"},"DESCRIZIONE","ANNO_RIF_INIZIO","ANNO_RIF_FINE","PREDEFINITO","AREE","UFFICI","ID_UTENTE"],"idProperty":"ID","successProperty":"success","root":"root"},"root":[{"ID":"33","ANNO_RIF_INIZIO":"2010","DESCRIZIONE":"ppppp","AREE":"1,2","PREDEFINITO":"N","TIMESTAMP":"2010-07-30 17:12:07","UFFICI":"1,4,5","ID_UTENTE":"1","ANNO_RIF_FINE":null}],"totalCounts":1}
Anyhow, it's all good as far as it deals with "read" calls. As it goes for a "create" there's and "undefined" parameter, sent to the server. That parameter holds up the data that should be held by "root", which of course is missing at all.
The record creation is defined as:
and server call goes with the following parameterCode:var recordClass = Ext.data.Record.create(gecalPdlFiltroStore.reader.meta.fields); gecalPdlFiltroStore.add(new recordClass({ ANNO_RIF_INIZIO: anno_rif_inizio, ANNO_RIF_FINE: anno_rif_fine, DESCRIZIONE: descrizione, PREDEFINITO: predefinito, AREE: aree, UFFICI: uffici }));
which, instead, should beCode:undefined: {"ANNO_RIF_INIZIO":2010,"ANNO_RIF_FINE":2020,"DESCRIZIONE":"prova","PREDEFINITO":"N","AREE":"1,2","UFFICI":"2,3,4","id":"ext-record-193"}
One more thing....I can't use gecalPdlFiltroStore.reader.fields nor gecalPdlFiltroStore.fields in record creation as it throws errors, so I guess I'm not handling record creation correctly?!Code:root: {"ANNO_RIF_INIZIO":2010,"ANNO_RIF_FINE":2020,"DESCRIZIONE":"prova","PREDEFINITO":"N","AREE":"1,2","UFFICI":"2,3,4","id":"ext-record-193"}
any help willl be very welcome
-
1 Aug 2010 11:43 PM #2
update
update
just to mention I changed the way a new record is created:
Now i think the record creation is correctly written.Code:var record = new gecalPdlFiltroStore.recordType({ ANNO_RIF_INIZIO: anno_rif_inizio, ANNO_RIF_FINE: anno_rif_fine, DESCRIZIONE: descrizione, PREDEFINITO: predefinito, AREE: aree, UFFICI: uffici }); gecalPdlFiltroStore.add(record);
However the error is still there....perhaps it's a bug?
-
2 Aug 2010 12:57 AM #3Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
1. You should create your reader with an empty fields array:
2. Can you check what gecalPdlFiltroStore.writer.meta.root is in the beforewrite event?Code:reader: new Ext.data.JsonReader({fields: []}),
-
2 Aug 2010 2:04 AM #4
1. I put in the correct reader definition:
reader: new Ext.data.JsonReader({fields: []})
but still it doesn't work
2. the gecalPdlFiltroStore.writer.meta.root property in beforewrite event (store) is undefined
regards
-
2 Aug 2010 2:55 AM #5Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
Which Ext version are you using (I just noticed that this was broken in Ext 3.0)?
-
2 Aug 2010 4:10 AM #6
I use extjs 3.0; can't use the latest version because of a 3rd party component which does not work under 3.1 or later versions;(
anyhow, if there's not a work around I'll just skip the meta definition supplied at server side
regards
-
2 Aug 2010 4:28 AM #7Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
In Ext 3.0 Ext.data.Store.onMetaChange forgets to copy the meta from reader to writer.
(compare the Ext.data.Store.onMetaChange code of Ext 3.0 with Ext 3.3)
-
26 Jan 2011 8:47 AM #8
Hi,
I have such a json served by php application. How to set JsonReader to work? I see my json file doesnt have "total" and "results"... Is it possible or should I rewrite my json application?
I tried to use this reader gave by Condor: reader: new Ext.data.JsonReader({fields: []}),
but it doesnt help.
Hmmm editor removed commas from my json example, but in fact it has.PHP Code:{"1": {id: "1"title: "Licencja"myfto_righttype_id: "2"date_start: "2010-12-23"date_end: "2011-12-16"notify: "10"enabled: "1"description: ""created_on: "0000-00-00 00:00:00"created_by: "0"modified_on: "2010-12-15 17:32:27"modified_by: "62"locked_on: "0000-00-00 00:00:00"locked_by: "0"type_title: "Licencja"user_name: ""}"3": {id: "3"title: "Badania Tomka"myfto_righttype_id: "3"date_start: "2012-12-20"date_end: "0000-00-00"notify: "0"enabled: "1"description: "Przypomnienie o badaniach."created_on: "2010-12-15 15:08:47"created_by: "62"modified_on: "2010-12-31 12:00:00"modified_by: "62"locked_on: "0000-00-00 00:00:00"locked_by: "0"type_title: "Badania"user_name: "Administrator"}}
-
26 Jan 2011 11:28 PM #9Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
You have an object instead of an array as root. You will need a custom root function for that:
Code:var reader = new Ext.data.JsonReader({ root: function(v){ var root = []; for (var p in v) { if (v.hasOwnProperty(p)) { root.push(v[p]); } } return root; }, fields: [ {name: 'id', type: 'int'}, {name: 'title', type: 'string'}, {name: 'myfto_righttype_id', type: 'int'}, {name: 'date_start', type: 'date', dateFormat: 'Y-n-j'}, {name: 'date_end', type: 'date', dateFormat: 'Y-n-j'}, {name: 'notify', type: 'bool'}, {name: 'enabled', type: 'bool'}, {name: 'description', type: 'string'}, {name: 'created_on', type: 'date', dateFormat: 'Y-n-j G:i:s'}, {name: 'created_by', type: 'int'}, {name: 'modified_on', type: 'date', dateFormat: 'Y-n-j G:i:s'}, {name: 'modified_by', type: 'int'}, {name: 'locked_on', type: 'date', dateFormat: 'Y-n-j G:i:s'}, {name: 'locked_by', type: 'int'}, {name: 'type_title', type: 'string'}, {name: 'user_name', type: 'string'}, ] });
-
31 Jan 2011 2:18 AM #10
Condor thank You very much, it helps me

Similar Threads
-
JsonReader, metaData: undefined root property on create action
By callipigia in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 30 Jul 2010, 7:48 AM -
[FIXED][3.0-r4925] JsonReader readResponse root === undefined is moot
By mjlecomte in forum Ext 3.x: BugsReplies: 1Last Post: 29 Jul 2009, 7:09 PM -
Problem with JsonReader : root is undefined
By infojin in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 8 Dec 2008, 12:26 AM -
specify root for grid metadata
By SunWuKung in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 21 Nov 2008, 1:39 AM


Reply With Quote