I am trying to get a collection of objects in JSON that have children
and iterate through the name properties of those children. For
example I want to get the collection of Furniture and return its
children.
I have tried to do this by converting the Object to a Hash and iterate
through it with an each. It seems to get the Objects but returns them
as undefined.
How can I return the names of the children in id:3 as strings?
Thanks,
Seamus
sample.json:
{
"id": 2,
"name": "Products",
"children": [
{ "id": 3, "name": "Furniture", "children":
[
{ "id": 4, "name": "Table", children: []},
{ "id": 5, "name": "Chair", children: []},
{ "id": 6, "name": "Lamp", children: []},
]
}
]
}
ajax.js:
var SomeObj = Class.create();
SomeObj.prototype = {
initialize: function(){
console.log("Hello");
},
getStuff: function(){
new Ajax.Request('/sample.json',
{
method:'get',
onSuccess: function(transport){
var json = transport.responseText.evalJSON();
$H(json).each(function(element){
console.log(json.children.name);
});
},
onFailure: function(){ console.log('Something went wrong...') }
});
}
}
Event.observe(document, "dom:loaded", function(){
someObj = new SomeObj;
someObj.getStuff();
});
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---