[英]Build an array in JavaScript to fill jsTree
I am trying to build a tree of files (for a web application) by using JsTree. 我正在尝试通过使用JsTree来构建一棵文件树(用于Web应用程序)。
I have different levels: 我有不同的水平:
level 1: dimension
1级: dimension
level 2: hierarchie
( dimension
's child) 级别2: hierarchie
( dimension
的子级)
level 3: niveau, Ordre_niveau = 1
( hierarchie
's child) 级别3: niveau, Ordre_niveau = 1
( hierarchie
的孩子)
level n: niveau, Ordre_niveau = n
( niveau ordre (n-1)
's child) 级别n: niveau, Ordre_niveau = n
( niveau ordre (n-1)
的孩子)
I succeed in filling dimension
and hierarchie
, but all my niveau
are at the same level because the information of ordre
is in the same object as the information of niveau
. 我成功地填充了dimension
和hierarchie
,但是我的所有niveau
处于同一级别,因为ordre
的信息与niveau
的信息在同一对象中。
Here is my code: 这是我的代码:
var jsTreeData = [];
//"dimensions"
for (var i = 0; i < dimension.length; i++) {
jsTreeData.push({
'text': dimension[i].dimension_Nom_dimension,
'type': 'dimension',
'data': dimension[i],
'children': []
});
//"hiérarchies"
var x = -1;
for (var j = 0; j < hierarchie.length; j++) {
if (hierarchie[j].dimension_Dimension_id == jsTreeData[i].data.dimension_Dimension_id) {
jsTreeData[i].children.push({
'text': hierarchie[j].hierarchie_Nom_hierarchie,
'type': 'hierarchie',
'data': hierarchie[j],
'children': []
});
x = x + 1;
//"niveaux"
for (var k = 0; k < niveau.length && x < (jsTreeData[i].children.length); k++) {
for (var l = 0; l < niveau.length && x < (jsTreeData[i].children.length); l++) {
if (niveau[k].hierarchie_Hierarchie_id == jsTreeData[i].children[x].data.hierarchie_Hierarchie_id && niveau[k].niveau_Niveau_id == niveau[l].niveau_Niveau_parent_id && niveau[k].niveau_Ordre_niveau == 1 && niveau[l].niveau_Ordre_niveau == 2) {
jsTreeData[i].children[x].children.push({
'text': niveau[k].niveau_Nom_niveau,
'type': 'niveau',
'data': niveau[k],
'children': ({
jsTreeData: ({
'text': niveau[l].niveau_Nom_niveau,
'type': 'niveau',
'data': niveau[l]
})
})
});
}
}
}
}
}
}
The result is that the Jstree display all the dimension
, all the hierarchie
but only the niveau, Ordre_niveau = 1
and not the niveau, Ordre_niveau = 2
, etc. 结果是Jstree显示所有dimension
,所有hierarchie
但仅显示niveau, Ordre_niveau = 1
,而不显示niveau, Ordre_niveau = 2
, niveau, Ordre_niveau = 2
。
It is like the property children
of Jstree doesn't work. 就像Jstree的children
级属性不起作用一样。
I don't understand you question, but you can use the easiest way to fix and debugging: console.log('Some label', variable);
我不明白您的问题,但是您可以使用最简单的方法进行修复和调试: console.log('Some label', variable);
Use it in every place where you have the if ... else
or for (i =0, ...)
or in other problem for you places. 在您拥有if ... else
或for (i =0, ...)
或您遇到其他问题的每个地方使用它。 It help you find errors or mistakes. 它可以帮助您发现错误或错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.