1. #1
    Ext User
    Join Date
    Apr 2009
    Posts
    14
    Vote Rating
    0
    Jim.Barrows is on a distinguished road

      0  

    Default How to parse class with array of classes, an another array of classes inside that.

    How to parse class with array of classes, an another array of classes inside that.


    let me start by saying, it's not my data model, and as much as it sucks... it sucks less then fixing it now. *SIGH*
    So here is what I have:
    Code:
    [ {
                            "actionTaken" :null,
                            "activityId" :"MAT  210",
                            "activityNo" :0,
                            "activityTitle" :"BRIEF CALCULUS",
                            "categories" : [ {
                                "areas" : [ {
                                    "appliedAreaId" :"GENERAL01",
                                    "appliedCredits" :null,
                                    "areaDescription" :null,
                                    "completedCredits" :null,
                                    "deficientCredits" :null,
                                    "oid" :17041552110,
                                    "priority" :null,
                                    "requiredCredits" :null,
                                    "studentActivitySequenceNumber" :"18185595"
                                } ],
                                "categoryDescription" :null,
                                "categoryId" :"REQUIRED",
                                "clasrostNo" :238134944,
                                "irn" :85467,
                                "priority" :0,
                                "tableName" :"applied_area"
                            } ],
                            "clasRostNo" :238134944,
                            "corpStudProgHistNo" :null,
                            "courseAlphaPrefix" :"",
                            "courseEvaluationStatus" :"P",
                            "courseNumber" :"",
                            "creditsAccepted" :0.0,
                            "creditsAttempted" :3.0,
                            "creditsEarned" :3.0,
                            "dateCreated" :null,
                            "dateModified" :null,
                            "dateOfCourse" :null,
                            "division" :"UPPER",
                            "evaluationStatus" :"PENDING_EVALUATION",
                            "evaluationType" :"",
                            "gradeSelected" :"A",
                            "grdeDate" :null,
                            "irn" :85467,
                            "month" :"01",
                            "nonTransferReason" :null,
                            "nonTransferReasonStr" :null,
                            "orgaNumber" :10034,
                            "programFreeze" : [],
                            "reuseCode" :"",
                            "reuseCodeOid" :0,
                            "reuseEvaluated" :"UPDATED_REUSE",
                            "statusOfNonTransferableReasons" :"NONE",
                            "statusOfTransferableCategories" :"BLOCK",
                            "targetInstId" :0,
                            "targetInstitutionId" :0,
                            "termDate" :"1970-01-01T00:00:00",
                            "transcriptOid" :120037555,
                            "transeferableStatus" :"TRANSFERABLE",
                            "unConvertedCredits" :3.0,
                            "userCreatedBy" :"",
                            "userModifiedBy" :"kabreitb",
                            "year" :"1970"
                        } ]
    I need to get categories[x].categoryId and categories[x].areas[y].areaId into a two column grid. So first I have to parse it in the data store... Which is where the trouble is.
    How the heck do I do that?
    Using a converter like so:
    Code:
    var CategoryModel = Ext.data.Record.create( [ {
      name :'areas',
      convert: function(v, rec) {                
        var reader = new Ext.data.ArrayReader( {root :'areas'}, AreaModel);
        var areaArray = reader.readRecords(v);
        return v;
      }}, {
    doesn't seem to work. Not really sure why.
    Passing the categories array to the JsonStore on the load event like so:
    Code:
    load : function(store, records, options) {
      for (i = 0; i < records.length; i++) {
        if (records[i].get('areas')) {
          var reader = new Ext.data.ArrayReader( {root :'areas'}, AreaModel);
          var areaArray = reader.read(records[i].get('areas'));
          records[i].set('areas', areaArray);
        }
      }
    }
    Also doesn't work.
    When i say doesn't work, I mean I don't end up with an array in areas like I need to. Can anyone tell me what I'm doing wrong? or am I just going to have to rewrite a major portion of the server side logic?

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I son't understand how that maps into a series of rows, each containing the same set of Fields.

    But you need to read the JsonReader API docs.

  3. #3
    Ext User
    Join Date
    Apr 2009
    Posts
    14
    Vote Rating
    0
    Jim.Barrows is on a distinguished road

      0  

    Default


    Oh, sorry. categories[x].categoryId and categories[x].areas[y].appliedAreaId are the two columns in the row. In this particular case there is only one area per category.
    I have read the JsonReader API docs. And was reading them again before you replied.. not sure what I'm missing.

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    OK, first steps...

    What is the "root" property that you ned in your JsonReader?

    All the info for you to work this out is in the JsonReader API docs.

  5. #5
    Ext User
    Join Date
    Apr 2009
    Posts
    14
    Vote Rating
    0
    Jim.Barrows is on a distinguished road

      0  

    Default


    The JSON I'm getting back from the server is exactly what I put into the comments. So if I catch your drift, I should be using the JsonReader for categories and areas, and not the ArrayReader. Which I just tried and readRecords and read don't work, they don't load the data... loadexception get's thrown.
    I have a json reader for the top level object... is it parsing all the way down?

  6. #6
    Ext User
    Join Date
    Apr 2009
    Posts
    14
    Vote Rating
    0
    Jim.Barrows is on a distinguished road

      0  

    Default


    Okay, so it's not parsing everything... Does categories and areas need to be type :'string' then? Right now they're not typed at all.....

  7. #7
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    It reads a repeating set of row objects.

    That is defined by the root config. Let's start there.

    I still can't see how you get a regular, tabular set of data from that blob.

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Is it categories that is the Array representing rows?

    Code:
                            "categories" : [ {
                                "areas" : [ {
                                    "appliedAreaId" :"GENERAL01",
                                    "appliedCredits" :null,
                                    "areaDescription" :null,
                                    "completedCredits" :null,
                                    "deficientCredits" :null,
                                    "oid" :17041552110,
                                    "priority" :null,
                                    "requiredCredits" :null,
                                    "studentActivitySequenceNumber" :"18185595"
                                } ],
                                "categoryDescription" :null,
                                "categoryId" :"REQUIRED",
                                "clasrostNo" :238134944,
                                "irn" :85467,
                                "priority" :0,
                                "tableName" :"applied_area"
                            } ],

  9. #9
    Ext User
    Join Date
    Apr 2009
    Posts
    14
    Vote Rating
    0
    Jim.Barrows is on a distinguished road

      0  

    Default


    Yes.

  10. #10
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    So root is "categories"

    And then each field's mapping is the javascript path relative to that from which to extract the value.

    And if that won't do it, you can use a field's convert property to specify a function which is passed the row object, and extracts just what you want and returns the field value.

Thread Participants: 1