Create Dynamic Variable using Loop
Hello,
What I am trying here to do is to create variable for views using for loop so I can use it in ScrollableView.
for e.g. here is what I did with no luck
var c=0;
for (c=0;c==3;c++)
{
var view +c = Ti.UI.createView({
backgroundColor:'red'
});
}
I want the loop to create variable such as
view0
view1
view2
Can anyone help me in this??
5 Answers
-
Accepted Answer
change the "while" loop to a "for" one, and the "view - new Array();" to "var view=[];"
here is a code that workshttp://pastie.org/974874
-
why don't you use an array?
var your_arr = []; for (c=0;c==3;c++) { your_arr[c] = Ti.UI.createView({ backgroundColor:'red' }); }
-
I tried using array but then the views doesn't show up in ScrollableView.
-
Maybe you are making some mistake on the variable scope, and the function that tries to find the array is not finding it. Post more code pastie maybe we can help you :)
-
Here is what I have done and not working for me: