-
array.push not cumulative?
I have an array ("parentArray") assigned as a data provider for a dropdown as so:
_global.parentArray = new Array();
_level0.parentCombo.dataProvider = parentArray;
I also have a main data array ("mainArray") which I use to store everything:
_global.mainArray = new Array();
mainArray = [
["", "", "", "", "", "", "", ""],
["ItemA", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", ""],
["ItemB", "", "", "", "", "", "", ""],
["ItemC", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", ""],
["", "", "", "", "", "", "", ""]
];
Now, anytime the mainArray is change, I want to rebuid the dropdown list. So, I proceed to clear the existing array, and then find all non-blank [0] column values and add them to the parentArray.
rebuildDropdown () {
parentArray.length = 0;
for (var i = 0; i < 6; ++i) {
if (mainArray[i][0] <> "") {
parentArray.push(mainArray[i][0]);
trace("mainArray val: "+mainArray[i][0]);
}
}
}
But, even with values in the mainArray, the dropdown only ever lists the last var pushed to the parentArray - not all three as should be in this case.
The trace shows all three values correctly. Any ideas? :0
Ahhhk!
-
Senior Member
Hi,
try using the dataProvider methods instead of the standard array methods when working with parentArray,
Code:
parentArray = [];
mainArray = [["", "", "", "", "", "", "", ""], ["ItemA", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", ""], ["ItemB", "", "", "", "", "", "", ""], ["ItemC", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", ""]];
a_cb.dataProvider = parentArray;
function rebuildDropdown() {
parentArray.removeAll();
for (var i = 0; i < 6; ++i) {
if (mainArray[i][0] != "") {
parentArray.addItem(mainArray[i][0]);
}
}
}
rebuildDropdown();
-
Well...sheet. I didnt even know there were dataProvider methods.
Learn something new every Sunday.
Thanks much, catbert303!
Ahhhk!
-
hrrmm....it seems that the parentArray.addItem isnt doing anything. Doing a trace on the Array indexes shows it all undefined.
Code:
parentArray.removeAll();
tempx = 0;
for (var i = 0; i < 6; ++i) {
if (mainArray[i][0] != "") {
parentArray.additem(mainArray[i][0]);
trace("mainArray value: "+mainArray[i][0]); <-- all correct
trace("parentArray insert: "+parentArray[tempx]); <--all undefined
++tempx;
}
}
Ok, haha...this is retarded. But, the dropdown was being populated correctly with my original code. Some how, the dropdown's rowCount got set to 1 - so only the last item was shown and the scroll bar was pretty much removed which lead me to believe there was only one item. <smaaaaaaaack!>
And, you need to specify the label and data when using additem for it to work. It works fine when use I this:
parentArray.addItem({label:mainArray[i][0], data:i})
Thanks!
Ahhhk!
Last edited by Ahhhk; 05-01-2005 at 04:39 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|