-
18 Oct 2009 7:04 AM #1
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
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?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..."
}
For access the the row I use
andPHP Code:var data = grid.store.getAt(rowIndex);
But how can I get access to keywords or authors?PHP Code:data.get('title');
Without knowing of the structure. Is it possible to access in another way like
RegardsPHP Code:data[a1] //for the first author
-
18 Oct 2009 7:45 AM #2
Try this
Try this
Try :-
var authors = data.get("AUTHOR");
var a1 = authors.a1;
-
18 Oct 2009 8:00 AM #3
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?
-
18 Oct 2009 9:57 AM #4
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?Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
19 Oct 2009 4:09 AM #5
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?
-
19 Oct 2009 4:44 AM #6
As I'm right, I have different record objects if I click in the grid on a row.
orCode:{ 1=Muhammad Raza 2=Farookh khadeer Hussain }
or moreCode:{ 1=Serge Abiteboul 2=Ohad Greenshpan 3=Tova Milo }
But how can I access this object without knowing the number of entries?
I use the convert method and have to arguments (v,record).
give me the record object, but how can I convert this object to an array?Code:record.author
Do I need in my convert method an extra reader for this object?
-
19 Oct 2009 7:14 AM #7
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.
-
19 Oct 2009 7:53 AM #8
ah okay, thanks for that. Now I found a way to convert the object into an array.
-
19 Oct 2009 11:11 AM #9
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.
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!
-
19 Oct 2009 11:16 AM #10
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.


Reply With Quote