1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    60
    Vote Rating
    0
    irishdunn is on a distinguished road

      0  

    Default JSONDataModel, Understanding schema

    JSONDataModel, Understanding schema


    I understand the schema for the XMLDataModel, mostly in part to the fact that XML is organized in tree form. When I look at a JSON object, there doesnt appear to be nodes in which to point the root of the schema to, I see all the attributes I want to pull out listed multiple times for multiple object that I want to see in the grid, but setting up the schema is escaping me...

    Do you have an example of what the data might look like and your schema?

    *EDIT*

    I might be back farther than I thought, when calling a web service I am returning to the callback function an object that is a list. This C# list several attributes including index's to the nodes that I want to parse into my JSONDataModel. So I downloaded this script to convert my list object into a JSON object (I allready might be on the wrong path).

    Now I have this rediculous string that I want to make a schema for

  2. #2
    Ext User
    Join Date
    Mar 2007
    Posts
    321
    Vote Rating
    0
    jbowman is on a distinguished road

      0  

    Default


    JSON pretty much is a javascript object. No real schema... it's an extremely lightweight way of passing data.

  3. #3
    Ext User
    Join Date
    Mar 2007
    Posts
    60
    Vote Rating
    0
    irishdunn is on a distinguished road

      0  

    Default


    I am getting back an object that has the data I want in it, but at this point it is a list so each iteration of the data I need has an index. I am not sure how to set up any of the datamodels for the grid to use what I have....

    therin lies the rub.


    *EDIT*

    here is my JSON data:

    Code:
    "[{\"__serverType\":\"CENSORED\",\"ID\":\"39c79afb-19a8-49fb-8d6a-f7c9d9db2b0e\",\"Comment\":\"\",\"PasswordAnswer\":\"\",\"CreationDate\":{},\"Email\":\"testAndrew@andrew.com\",\"IsApproved\":true,\"IsLockedOut\":false,\"IsOnline\":false,\"LastActivityDate\":{},\"LastLockoutDate\":{},\"LastLoginDate\":{},\"LastPasswordChangedDate\":{},\"PasswordQuestion\":\"nothing\",\"ProviderName\":\"NTKMembershipProvider\",\"ProviderUserKey\":{},\"UserName\":\"Test Andrew\"},
    
    {\"__serverType\":\"CENSORED\",\"ID\":\"5dfbae14-a4a1-4a16-add9-808c9ab794cb\",\"Comment\":\"\",\"PasswordAnswer\":\"\",\"CreationDate\":{},\"Email\":\"test@test.com\",\"IsApproved\":true,\"IsLockedOut\":false,\"IsOnline\":false,\"LastActivityDate\":{},\"LastLockoutDate\":{},\"LastLoginDate\":{},\"LastPasswordChangedDate\":{},\"PasswordQuestion\":\"nothing\",\"ProviderName\":\"NTKMembershipProvider\",\"ProviderUserKey\":{},\"UserName\":\"test Andrew2\"},
    
    {\"__serverType\":\"CENSORED\",\"ID\":\"b28b1bac-d678-4b07-aa36-129f08c26f90\",\"Comment\":\"\",\"PasswordAnswer\":\"\",\"CreationDate\":{},\"Email\":\"wstest@email.com\",\"IsApproved\":true,\"IsLockedOut\":false,\"IsOnline\":false,\"LastActivityDate\":{},\"LastLockoutDate\":{},\"LastLoginDate\":{},\"LastPasswordChangedDate\":{},\"PasswordQuestion\":\"color\",\"ProviderName\":\"NTKMembershipProvider\",\"ProviderUserKey\":{},\"UserName\":\"wstest\"}]"
    I split it up nice so there is three nodes, now here is the schema i am trying:

    Code:
                this.schema = {
                     root: '__serverType',
                     id: 'ASIN',
                     fields: ['UserName']
                };
    helps!

  4. #4
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Your JSON data has no root. The root is the array. This is bad JSON data as the root should be an object not an array.

  5. #5
    Ext User
    Join Date
    Mar 2007
    Posts
    321
    Vote Rating
    0
    jbowman is on a distinguished road

      0  

    Default


    I thought it looked funky, nds that's why I didn't reply as I was going to look it up, then got sidetracked playing with new data modeling software.

  6. #6
    Ext User
    Join Date
    Mar 2007
    Posts
    60
    Vote Rating
    0
    irishdunn is on a distinguished road

      0  

    Default


    Allright I do get an object back from the server with an array inside, but I dont know how to configure the schema for that... lemme give u a picture of my watch in VS



    So I gave up on the idea of using the JSONDataModel and now I am trying to dynamically build the DefaultDataModel...

    Code:
            function CallBack(value)
            {
                alert("CallBack Initiated");    
                var data;
                var datacount = value.get_length();
                alert("There are "+datacount+" items to be\n loaded into the grid");
                
                data = "[";
                for(i=0; i<datacount; i++)
                {
                    data = data + "['" + value[i].UserName + "']";
                    if(i<datacount-1)
                    {
                        data = data + ",";
                    }
                }
                data = data + "]";
                
                debugger
                
                this.griddata.removeAll();
                this.griddata.addRows(data);
            }
    But does the value for DefaultDataModel have to be an array? not a string which I am building.

    *EDIT*

    so to my disgust I realized I just built a nice string when the implementation should be a multidemensional array. I really would like to know how to implement the JSONDataModel, since the default datamodel generation is looking to be a headache now.

  7. #7
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Set your "schema" to the root of "data". Then add this code to your data model:

    Code:
    dataModel.loadData = function(data, callback, keepExisting){
        var objData = {'data': data};
        YAHOO.ext.grid.JSONDataModel.prototype.loadData.call(this, objData, callback, keepExisting);
    };
    This will make your array part of the object "objData" with a root of "data" so you can access it.

  8. #8
    Ext User
    Join Date
    Mar 2007
    Posts
    60
    Vote Rating
    0
    irishdunn is on a distinguished road

      0  

    Default


    That code extends my object's attributes down from data, so now I have a root which is great but the scheme still will not pull out the attributes I want.

    Code:
                var schema = {
                 root: 'data',
                 id: 'ASIN',
                 fields: ['UserName']
                };
    so now I have my objData
    data
    attribute
    attribute
    attribute
    [0] <------ The field I want is in here
    [1] <------ The field I want is in here
    [2] <------ The field I want is in here

    Still escaping me....

  9. #9
    Ext User
    Join Date
    Mar 2007
    Posts
    60
    Vote Rating
    0
    irishdunn is on a distinguished road

      0  

    Default


    can i get a little help here guys? this is really frustrating. I think my web services are written correctly, but I keep getting this object back. I really want to tie this in with my yui interface!

  10. #10
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    So what does your JSON object look like now? Can you dump it (Object.dump(o)) and paste in the data (abbreviated)?

Similar Threads

  1. JSONDataModel how to access a custom value from schema?
    By neongrau in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 27 Feb 2007, 3:58 AM
  2. understanding loadScripts
    By jbowman in forum Community Discussion
    Replies: 1
    Last Post: 17 Nov 2006, 9:20 AM
  3. re: I need basic understanding of where to start
    By tryanDLS in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 14 Nov 2006, 2:07 PM
  4. I need basic understanding of where to start
    By tryanDLS in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 14 Nov 2006, 2:02 PM
  5. I need basic understanding of where to start
    By tryanDLS in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 14 Nov 2006, 1:54 PM

Thread Participants: 2