Reputation: 1247
I'm trying to increase the row each time around the loop, but it's not increasing is there something wrong with my JavaScript code?
var image= [];
for (var i = 0; i < test.length; i++) {
var avatar = test[i].image; // The profile image
var row =5;
if(i % 2 === 0){
image[i]= Titanium.UI.createImageView({
top:row,
image:avatar
});
win.add(image[i]);
//trying to increase the image
row =row+200;
} else if(i % 2 === 1) {
image[i]= Titanium.UI.createImageView({
top:row,
image:avatar
});
win.add(image[i]);
}
}
Upvotes: 0
Views: 279
Reputation: 9955
You are initializing row in each start of loop. Try taking your var row = 5 outside of the loop:
var image= [];
var row =5;
for (var i = 0; i < test.length; i++) {
var avatar = test[i].image; // The profile image
...
}
Upvotes: 1
Reputation: 5545
try to move this line upper outside of the loop :
var image= [];
var row =5;
for (var i = 0; i < test.length; i++) {
...
}
Upvotes: 1
Reputation: 15892
Can't say I'm certain of what you're attempting to achieve, but at the beginning of your for
iteration you're resting row
to 5. You should move your var row=5;
declaration to the top with var image[];
You might also consider the short form row+=200;
Upvotes: 3