gpt4 book ai didi

javascript - 如何将 JSON 数据与 Bootstrap 树一起使用?

转载 作者:太空宇宙 更新时间:2023-11-04 16:22:38 29 4
gpt4 key购买 nike

我正在尝试使用 Bootstrap 树来获取 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
}

]
}
...
];

在代码末尾,我期望得到如下结果:

Here is the expected result

但是http://jonmiles.github.io/bootstrap-treeview代码使用这样的数据:

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 代替文本吗?或者我可以做些什么来达到我的预期结果吗?我没有找到任何相关信息。

最佳答案

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

关于javascript - 如何将 JSON 数据与 Bootstrap 树一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40475185/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com