1

I'm trying to get some data into this format, for use with a templating system called mustache:

{
  "repo": [
    { "name": "resque" },
    { "name": "hub" },
    { "name": "rip" },
  ]
}

and what I currently have is this:

for (childIndex in scenes[sceneID].children) {  
    childSceneID = scenes[sceneID].children[childIndex];
    childScene = scenes[childSceneID];
}

So I somehow need to make each childScene the "name" in the "repo" object. Does anyone know how to do this? This is the mustache documentation:

http://mustache.github.com/mustache.5.html

3
  • Which name in the repo object? There are 3 different ones. Commented Aug 15, 2011 at 21:50
  • possible duplicate of javascript and mustache - passing an array to template Commented Aug 15, 2011 at 21:50
  • Sorry - I couldn't delete that question, but I think this is more to the point of what I'm trying to solve. Each childscene would be a name, and those names would be pushed as part of the overall template object. Commented Aug 15, 2011 at 21:52

2 Answers 2

1

Is this what you meant?:

var repo = [];

for (childIndex in scenes[sceneID].children) {  
    childSceneID = scenes[sceneID].children[childIndex];
    childScene = scenes[childSceneID];
    repo.push({"name": childScene});
}

var theobj = { "repo": repo };
Sign up to request clarification or add additional context in comments.

1 Comment

@mheavers I spelt child wrong before, I had childe. Was that the problem?
0

I just put this here

var repo = new Object();
var table = new Object();
repo["repo"] = table;
table["name1"] = "resque";
table["name1"] = "hub";
table["name1"] = "rip";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.