1

我正在尝试将一些数据转换为这种格式,以用于名为 mustache 的模板系统:

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

我目前拥有的是:

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

所以我需要以某种方式使每个 childScene 成为“repo”对象中的“名称”。有谁知道如何做到这一点?这是胡子文档:

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

4

2 回答 2

1

这是你的意思吗?:

var repo = [];

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

var theobj = { "repo": repo };
于 2011-08-15T21:50:39.203 回答
0

我只是把这个放在这里

var repo = new Object();
var table = new Object();
repo["repo"] = table;
table["name1"] = "resque";
table["name1"] = "hub";
table["name1"] = "rip";
于 2011-08-15T21:58:03.527 回答