Answer the question
In order to leave comments, you need to log in
js return value problem?
there is a function code
function Name(){
........
var ept = getArrayFromTree(path.split("/"), null);
console.log("1", ept);
}
function getArrayFromTree(step_to, now_arr){
......
else{
console.log("2",now_arr);
return now_arr;
}
}
2 {выводится то что нужно}
1 undefined
<script type="text/javascript">
var tree = document.getElementById("qwe").innerHTML;
tree = JSON.parse(tree);
var new_images = document.getElementById("new_images");
generetaImagesFolders("");
function generetaImagesFolders(path){
var now = document.getElementById("new_images_path_now").innerHTML;
var step_to = now+path;
document.getElementById("new_images_path_now").innerHTML = step_to;
new_images.innerHTML = "";
var ept = getArrayFromTree(path.split("/"), null);
console.log("1", ept);
for( key in ept){
new_images.innerHTML += "<div data-name-path='"+key+"'>"+key+"</div>";
}
renewEvents();
}
function renewEvents(){
var sometings = new_images.querySelectorAll("div");
for(var i = 0; i<sometings.length; i++){
sometings[i].onclick = function(){
// console.log(this.getAttribute('data-name-path'));
generetaImagesFolders(this.getAttribute('data-name-path'));
}
}
}
function getArrayFromTree(step_to, now_arr){
if(now_arr === null) {
now_arr = tree;
}
var first = step_to.shift();
if(first !== "" && first !== undefined) {
getArrayFromTree(step_to, now_arr[first]);
}
else{
console.log("2",now_arr);
return now_arr;
}
}
</script>
Answer the question
In order to leave comments, you need to log in
Maybe it just doesn't return there? Can I have the full code for the second function?
I didn’t look much, but offhand try adding returnreturn getArrayFromTree(step_to, now_arr[first]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question