Open LordRhialto opened 5 years ago
gijgo-combined-1.9.11/js/gijgo.js and early versions This is a bag in the : pathFinder: function (data, list, id, parents) { var i, result = false;
for (i = 0; i < list.length; i++) {
if (list[i].id == id) {
result = true;
break;
} else
{
if (gj.tree.methods.pathFinder(data, list[i][data.childrenField], id, parents)) {
// parents.push(list[i].data[data.textField]); // original with error
parents.push(list[i][data.textField]); // my correction, it works for me
result = true;
break;
}
}
}
return result;
}
ps: you must define primaryKey: 'id' in yor tree init statement!!!
$('#tree').tree({ primaryKey: 'id', dataSource: [ { id: 101, text: 'foo', children: [ { id: 202, text: 'bar' } ] } ], select: function (e, node, id) { alert('Your key is ' + id); } });
Any update on this? Fixing the line above fixes the error, but parents are still returned as an empty array. This includes when setting the primaryKey in the init. This would be super helpful to have this working.
+1
how the progress ? i also face the case
Anyone feel free to make a pull request
Fix:
pathFinder: function (data, list, id, parents) {
var i, result = false;
if (typeof list !== undefined && list !== null) {
for (i = 0; i < list.length; i++) {
if (list[i].id == id) {
result = true;
break;
} else if (gj.tree.methods.pathFinder(data, list[i][data.childrenField], id, parents)) {
parents.push(list[i][data.textField]);
result = true;
break;
}
}
}
return result;
}
Or if you want to place your fix in a seperate file:
$.extend(gj.tree.methods, {
pathFinder: function (data, list, id, parents) {
var i, result = false;
if (typeof list !== undefined && list !== null) {
for (i = 0; i < list.length; i++) {
if (list[i].id == id) {
result = true;
break;
} else if (gj.tree.methods.pathFinder(data, list[i][data.childrenField], id, parents)) {
parents.push(list[i][data.textField]);
result = true;
break;
}
}
}
return result;
}
});
I'm trying to find the parents of a specific node, but the code crashes on line 10709 (parents.push(list[i].data[data.textField]);) of the gijgo.js file (v1.9.11).
`<!DOCTYPE HTML>
Tree view
`