Javascript 如何在引导树中使用JSON数据?

Javascript 如何在引导树中使用JSON数据?,javascript,json,twitter-bootstrap,treeview,Javascript,Json,Twitter Bootstrap,Treeview,我正在尝试使用引导树来处理JSON数据。我生成的JSON数据如下: var newData = [ { "resName": "LYS", "atoms": [ { "atomName": "N",

我正在尝试使用引导树来处理JSON数据。我生成的JSON数据如下:

var newData = [

                {
                    "resName": "LYS",
                    "atoms": [

                            {
                                "atomName": "N",
                                "x": 37.995,
                                "y": 20.521,
                                "z": 9.231
                            },
                            {
                                "atomName": "CA",
                                "x": 38.067,
                                "y": 19.342,
                                "z": 10.141
                            }

                        ]
                }
...
            ];
var defaultData = [
              {
                text: 'Parent 1',
                href: '#parent1',
                tags: ['4'],
                nodes: [
                  {
                    text: 'Child 1',
                    href: '#child1',
                    tags: ['2'],
                    nodes: [
                      {
                        text: 'Grandchild 1',
                        href: '#grandchild1',
                        tags: ['0']
                      },
                      {
                        text: 'Grandchild 2',
                        href: '#grandchild2',
                        tags: ['0']
                      }
                    ]
                  },
                  {
                    text: 'Child 2',
                    href: '#child2',
                    tags: ['0']
                  }
                ]
              },
              {
                text: 'Parent 2',
                href: '#parent2',
                tags: ['0']
              }
            ];
在代码末尾,我希望得到如下结果:

var newData = [

                {
                    "resName": "LYS",
                    "atoms": [

                            {
                                "atomName": "N",
                                "x": 37.995,
                                "y": 20.521,
                                "z": 9.231
                            },
                            {
                                "atomName": "CA",
                                "x": 38.067,
                                "y": 19.342,
                                "z": 10.141
                            }

                        ]
                }
...
            ];
var defaultData = [
              {
                text: 'Parent 1',
                href: '#parent1',
                tags: ['4'],
                nodes: [
                  {
                    text: 'Child 1',
                    href: '#child1',
                    tags: ['2'],
                    nodes: [
                      {
                        text: 'Grandchild 1',
                        href: '#grandchild1',
                        tags: ['0']
                      },
                      {
                        text: 'Grandchild 2',
                        href: '#grandchild2',
                        tags: ['0']
                      }
                    ]
                  },
                  {
                    text: 'Child 2',
                    href: '#child2',
                    tags: ['0']
                  }
                ]
              },
              {
                text: 'Parent 2',
                href: '#parent2',
                tags: ['0']
              }
            ];

但代码使用的数据如下所示:

var newData = [

                {
                    "resName": "LYS",
                    "atoms": [

                            {
                                "atomName": "N",
                                "x": 37.995,
                                "y": 20.521,
                                "z": 9.231
                            },
                            {
                                "atomName": "CA",
                                "x": 38.067,
                                "y": 19.342,
                                "z": 10.141
                            }

                        ]
                }
...
            ];
var defaultData = [
              {
                text: 'Parent 1',
                href: '#parent1',
                tags: ['4'],
                nodes: [
                  {
                    text: 'Child 1',
                    href: '#child1',
                    tags: ['2'],
                    nodes: [
                      {
                        text: 'Grandchild 1',
                        href: '#grandchild1',
                        tags: ['0']
                      },
                      {
                        text: 'Grandchild 2',
                        href: '#grandchild2',
                        tags: ['0']
                      }
                    ]
                  },
                  {
                    text: 'Child 2',
                    href: '#child2',
                    tags: ['0']
                  }
                ]
              },
              {
                text: 'Parent 2',
                href: '#parent2',
                tags: ['0']
              }
            ];

我可以用resName或atoms代替文本吗?或者我能做些什么来达到我的预期结果?我没有找到任何关于它的信息。

这是
JSON
格式的
bootstrap treeview
库,如果您想根据自定义的
JSON
数据创建树,那么您需要对
bootstrap treeview
js进行更改,并用
JSON
键替换
bootstrap
广义的
JSON
键,但您需要确保它不会破坏任何东西。

我明白了。谢谢你的回答。