开发者

javascript / jquery - creating an object in a particular format from a loop

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开发者_JS百科 mustache documentation:

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


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 };


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";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜