For some reason this statement is skipping some data.Am I missing a continue statement somewhere or something ? Here is the code
for (var i = 0, len = data.ORDER_STATUS[0].ORDERS.length; i < len; i++) {
if (data.ORDER_STATUS[0].ORDERS[i].SEC_TYPE == "MLEG") {
for (var i = 0; i < data.ORDER_STATUS[0].ORDERS[i].LEGS.length; i++) {
LEGS += '<tr class="MLEGS"><td class="orderFirst">' +
data.ORDER_STATUS[0].ORDERS[i].LEGS[i].SYMBOL +
'</td><td>' + data.ORDER_STATUS[0].ORDERS[i].LEGS[i].ACTION +
'</td><td>' + data.ORDER_STATUS[0].ORDERS[i].LEGS[i].QTY +
'</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
}
}
}
-
3Why in the world is it formatted like that? It looks like it's generated from a template file or something.Jared Farrish– Jared Farrish2011年08月15日 23:07:53 +00:00Commented Aug 15, 2011 at 23:07
-
should you be using the i variable both times?bozdoz– bozdoz2011年08月15日 23:09:08 +00:00Commented Aug 15, 2011 at 23:09
2 Answers 2
Use a different variable on the inner loop, like j instead of i.
for (var i = 0, len=data.ORDER_STATUS[0].ORDERS.length; i < len; i++) {
//...
for (var j = 0; j < data.ORDER_STATUS[0].ORDERS[i].LEGS.length; j++){
//...
data.ORDER_STATUS[0].ORDERS[i].LEGS[j].SYMBOL +
answered Aug 15, 2011 at 23:07
user113716
323k64 gold badges454 silver badges441 bronze badges
Sign up to request clarification or add additional context in comments.
7 Comments
Bootleg
That definitely works, but now the inner loop is only returning the first array key in that object when there are 4. hmmm
user113716
@Bootleg: I would need to see your
data to know why. Could you post it in the question?user113716
@Bootleg: Any errors in the console? Hard to tell from an image what's going on. Could you posted your updated code in your question? Don't erase the original code. Just put the new code at the bottom.
user113716
@Bootleg: Ah those tricky CSS issues! Not a problem. Glad you got it figured out.
user113716
@Greg: Thank you for pointing that out. I forgot to update that variable. But let me tell you something. You don't need to down-vote every time someone makes a minor mistake. I help to correct people's answers all the time without down-voting. I corrected yours the other day without down-voting you (or the others who had incorrect answers). In fact it's rare that I vote anyone down. If you look at my profile, you'll see that of my 3,434 votes, 96 are down. I'd rather help someone...
|
you are using "i" in your outer an inner loops. you need to use a different variable in the inner loop: i have used "inner" below as and example.
for (var i = 0, len=data.ORDER_STATUS[0].ORDERS.length; i < len; i++) {
if (data.ORDER_STATUS[0].ORDERS[i].SEC_TYPE=="MLEG"){
for (var inner = 0; inner < data.ORDER_STATUS[0].ORDERS[i].LEGS.length; inner ++) {
// do something
}
}
}
answered Aug 15, 2011 at 23:08
Dave
3,8825 gold badges33 silver badges39 bronze badges
Comments
Explore related questions
See similar questions with these tags.
lang-js