1. #1
    Ext User
    Join Date
    Oct 2009
    Location
    Italy
    Posts
    16
    Vote Rating
    0
    callipigia is on a distinguished road

      0  

    Default 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:

    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);
                }
            }
        }
    });
    the server response, on each calls, includes the metaData definition as of:

    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}
    that's just an example to figure out what the reader gets for its metaData definition.

    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:

    Code:
                    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                
                    }));
    and server call goes with the following parameter

    Code:
    undefined: {"ANNO_RIF_INIZIO":2010,"ANNO_RIF_FINE":2020,"DESCRIZIONE":"prova","PREDEFINITO":"N","AREE":"1,2","UFFICI":"2,3,4","id":"ext-record-193"}
    which, instead, should be

    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"}
    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?!

    any help willl be very welcome

  2. #2
    Ext User
    Join Date
    Oct 2009
    Location
    Italy
    Posts
    16
    Vote Rating
    0
    callipigia is on a distinguished road

      0  

    Default update

    update


    just to mention I changed the way a new record is created:

    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);
    Now i think the record creation is correctly written.
    However the error is still there....perhaps it's a bug?

  3. #3
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    1. You should create your reader with an empty fields array:
    Code:
    reader: new Ext.data.JsonReader({fields: []}),
    2. Can you check what gecalPdlFiltroStore.writer.meta.root is in the beforewrite event?

  4. #4
    Ext User
    Join Date
    Oct 2009
    Location
    Italy
    Posts
    16
    Vote Rating
    0
    callipigia is on a distinguished road

      0  

    Default


    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

  5. #5
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Which Ext version are you using (I just noticed that this was broken in Ext 3.0)?

  6. #6
    Ext User
    Join Date
    Oct 2009
    Location
    Italy
    Posts
    16
    Vote Rating
    0
    callipigia is on a distinguished road

      0  

    Default


    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

  7. #7
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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)

  8. #8
    Ext User
    Join Date
    Jan 2011
    Location
    Poland
    Posts
    2
    Vote Rating
    0
    jafeth is on a distinguished road

      0  

    Default


    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.

    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"}} 
    Hmmm editor removed commas from my json example, but in fact it has.

  9. #9
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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'},
        ]
    });

  10. #10
    Ext User
    Join Date
    Jan 2011
    Location
    Poland
    Posts
    2
    Vote Rating
    0
    jafeth is on a distinguished road

      0  

    Default


    Condor thank You very much, it helps me

Similar Threads

  1. JsonReader, metaData: undefined root property on create action
    By callipigia in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 30 Jul 2010, 7:48 AM
  2. Replies: 1
    Last Post: 29 Jul 2009, 7:09 PM
  3. Problem with JsonReader : root is undefined
    By infojin in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 8 Dec 2008, 12:26 AM
  4. specify root for grid metadata
    By SunWuKung in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 21 Nov 2008, 1:39 AM

Thread Participants: 2

Tags for this Thread