1. #1
    Sencha User
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    60
    Vote Rating
    0
    Robert82 is on a distinguished road

      0  

    Default access to an JSON object within a JSON Object

    access to an JSON object within a JSON Object


    Hello again

    I have another problem with the row access in a grid.

    I use the following JSON

    PHP Code:
    documents:[
                {
                    
    title:"A methodology for quality-based mashup of data sources",
                    
    author:{
                        
    a1:"Muhammad Raza",
                        
    a2:"Farookh khadeer Hussain",
                        
    a3:"Elizabeth Chang"
                    
    },
                    
    year:"2008",
                    
    conference:"Proceedings of the 10th International Conference on Information Integration and " +
                            
    "Web-based Applications & Services ",
                    
    keywords:{
                        
    k1:"CCCI metrics",
                        
    k2:"mashup",
                        
    k3:"quality",
                        
    k4:"reputation",
                        
    k5:"trust"
                    
    },
                    
    abstrakt:"The concept of mashup is gaining tremendous popularity and its application can be seen..."
                

    and it works fine for the strings, but I have an object within the JSON like author or keywords. How can I display these objects in my grid and the next step. How can I get one string from these objects?

    For access the the row I use
    PHP Code:
    var data grid.store.getAt(rowIndex); 
    and
    PHP Code:
    data.get('title'); 
    But how can I get access to keywords or authors?
    Without knowing of the structure. Is it possible to access in another way like
    PHP Code:
    data[a1//for the first author 
    Regards

  2. #2
    Ext JS Premium Member
    Join Date
    Nov 2007
    Location
    Cambridge UK
    Posts
    112
    Vote Rating
    0
    hat27533 is on a distinguished road

      0  

    Default Try this

    Try this


    Try :-

    var authors = data.get("AUTHOR");

    var a1 = authors.a1;

  3. #3
    Sencha User
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    60
    Vote Rating
    0
    Robert82 is on a distinguished road

      0  

    Default


    the count of authors is variable - how can I get all of them, when I don't know the count?

    Could I transform the Object in an Array? Or is it enough for an output in a View that i use an template and than iterate?

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

      0  

    Default


    http://www.extjs.com/deploy/dev/docs...member=convert

    So you can create a Field who's value is an Array.

    Then it's up to you how to present that info in a Grid row. How do you propose it looks?

  5. #5
    Sencha User
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    60
    Vote Rating
    0
    Robert82 is on a distinguished road

      0  

    Default


    Thanks animal for the hint - I will try it.

    I want to use the data in two panels and one grid. The grid should display the values in one row but every value among each other. The 2 panels should use different templates to display the values.

    I hope this is possible, if I fire an custom event and the panels listen to it and get the data.
    My thought was, that the panels have an extra store associated to the given data and then they could display it.

    Or is there an easier way?
    Is it possible to display in one grid row more than one lines?

  6. #6
    Sencha User
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    60
    Vote Rating
    0
    Robert82 is on a distinguished road

      0  

    Default


    As I'm right, I have different record objects if I click in the grid on a row.

    Code:
    { 1=Muhammad Raza 2=Farookh khadeer Hussain }
    or
    Code:
    { 1=Serge Abiteboul 2=Ohad Greenshpan 3=Tova Milo }
    or more

    But how can I access this object without knowing the number of entries?
    I use the convert method and have to arguments (v,record).
    Code:
    record.author
    give me the record object, but how can I convert this object to an array?
    Do I need in my convert method an extra reader for this object?

  7. #7
    Ext User
    Join Date
    Aug 2009
    Posts
    588
    Vote Rating
    1
    Mike Robinson is on a distinguished road

      0  

    Default


    In your original post, you presented the first element in an array called "documents."

    This element is an object with attributes such as "title" and "authors," some of which are, in turn, other objects.

    In the case of "authors," the object is a structure with keys such as "a3" and "a5." It is not, for example, "an array of strings." So be it.

    A syntax such as "author[a1]" implies (incorrectly) that "author" is an array, and that the variable "a1" (it could just as well be "xyzzy") contains an integer index into that array. (But "author" is not an array...)

    JavaScript allows you to create arbitrary structures and arrays containing other structures and arrays, e.g. "documents[0].author.a1." The web abounds with tutorials on this particular subject.

  8. #8
    Sencha User
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    60
    Vote Rating
    0
    Robert82 is on a distinguished road

      0  

    Default


    ah okay, thanks for that. Now I found a way to convert the object into an array.

  9. #9
    Ext User
    Join Date
    Aug 2009
    Posts
    588
    Vote Rating
    1
    Mike Robinson is on a distinguished road

      0  

    Default


    Basically, you've got three sorts of "things" that you see everywhere in JavaScript-land:
    • functions (which are actually discrete "things" ... a.k.a. mumble-mumble "closures")
    • arrays (which use a zero-based integer index)
    • structures, "hashes," call 'em what you like ... a collection of values identified by keys.
    You can "mix these up" in a lot of different ways.

    It seemed to me, when I first read this post, that "author" would be more-aptly described as an "array of strings" instead of as a structure with keys of the form "an" (for some "n"). It's sort-of like repeating the same sin of SQL, "don't have 'repeating groups' ... use 'one-to-many.'" Well, that's literally just what this is: one "document" has zero/one-or-more "authors" (also "keywords").

    Now, you do not always have control of such things, but if you do have control of both the client and the server side, it's something to think about. To my first-blush, each 'author' is simply a 'name' (it could of course be any sort of structure...), and there are 'zero or more of them, all alike,' and 'you don't know or care how many.' Ergo, a good candidate for using an array. Ditto for "keywords."

    Otherwise, the general representation .. the overall arrangement of a single documents entry and the idea of "an array of these things," seems really-good to me. HTH!

  10. #10
    Ext User
    Join Date
    Oct 2009
    Posts
    1
    Vote Rating
    0
    cyflaso is on a distinguished road

      0  

    Default


    I am not so hopeful. We'd have heard about it long before now.Plus, I would probably have had to pay for a computer upgrade.