$.each loop

Joined
Jul 9, 2023
Messages
25
Reaction score
0
hello
By modifying the current code, the result should come out like TO-BE.

How should I modify the TO-BE code?

current.png

TOBE.png
 
Joined
Sep 4, 2022
Messages
128
Reaction score
16
Hello !

you have to include your AJAX call in the first 'loop' to achieve.
a copy paste will fit.

change the place of the Ajax, put it in the main loop
 
Joined
Jul 9, 2023
Messages
25
Reaction score
0
Hello !

you have to include your AJAX call in the first 'loop' to achieve.
a copy paste will fit.

change the place of the Ajax, put it in the main loop

What position is the first 'loop' you mentioned? ===>

current.png


TOBE.png
 
Last edited:
Joined
Jul 9, 2023
Messages
25
Reaction score
0
Hello !

you have to include your AJAX call in the first 'loop' to achieve.
a copy paste will fit.

change the place of the Ajax, put it in the main loop
If [return false] ,
I want to break out of
②each (loop).
===> When [return false] , to escape ②each (loop), how should I write the code?

After that,
If it is [returns false],
I want
it to go straight to ajax.
 
Joined
Jul 4, 2023
Messages
366
Reaction score
41
If I getting you right, the code should be looks like similar to this ...

JavaScript:
$.(#combobox).each(function() {
  var stage = $.(this).val();

  $.each(ArrayList, function(idx, item) {
    $.each(item, function(idx2, item2) {
      if(stage == item2.toString()) {
        goStraightToAjax();
        return false;
      } else { // if(false)
        break; // break out of 2each loop 
      }
    });
  });
});

function goStraightToAjax() {
  var argData = {
    ...
  }
  $.ajax({
    method: 'post',
    url: './api/abc.xml'
  })
  .done(function(data) {
    var value = JSON.parse(data);
  });
}
 
Joined
Jul 9, 2023
Messages
25
Reaction score
0
If I getting you right, the code should be looks like similar to this ...

JavaScript:
$.(#combobox).each(function() {
  var stage = $.(this).val();

  $.each(ArrayList, function(idx, item) {
    $.each(item, function(idx2, item2) {
      if(stage == item2.toString()) {
        goStraightToAjax();
        return false;
      } else { // if(false)
        break; // break out of 2each loop
      }
    });
  });
});

function goStraightToAjax() {
  var argData = {
    ...
  }
  $.ajax({
    method: 'post',
    url: './api/abc.xml'
  })
  .done(function(data) {
    var value = JSON.parse(data);
  });
}


break; // break out of 2each loop

==>Error : Illegegal break statment uncaught
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top