Highlighted

ListItem <=> Array (ExtendScript)

Explorer ,
Aug 06, 2020

Copy link to clipboard

Copied

I'm trying to use a selection from a multiline listbox as arguments in a function, but It does not work.

If I'm testing it with an static array as test-argument everything works fine -  the testing structure tells me that it is an array and tells me "yes" when I ask it if it contains "Element 2" (var selectableTypes as argument instead of myDropdown.selection).

 

But if I send a ListItem it tells me it is an array but "no" at the test afterwards.

Corvin0_1-1596717030511.pngCorvin0_2-1596717041269.png

 

 

And If I add another test asking for array elements 0 and 1, it crashes completely with this error:

Corvin0_0-1596716866557.png

 

Remember, that it told me it IS an array before, but it looks like it is not one at the same time...I'm confused 😉

 

myPanel = new Window ('dialog {orientation:"row"}'); 

var selectableTypes = ["Element 1","Element 2","Element 3"];

// UI ************************************
var myGrp = myPanel.add('group {orientation:"row", alignChildren:"fill"}');
var myDropdown = myGrp.add("listbox", [0,0,200,200], selectableTypes, {scrolling: true, multiselect: true});
var myButton = myGrp.add("button",[0,0,100,20],"Select");
//****************************************

myButton.onClick = function (){selectLayers(myDropdown.selection);}
function selectLayers(mySelection){
alert (mySelection[0]+" and "+mySelection[1]); // This test breaks it with the ListItem!
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
    if(mySelection.indexOf("Element2") > -1){ // Select by Type
        alert(" YES");
        }else {
            alert(" NO");
            }
       }

myPanel.center();
myPanel.show();

 

So, only 10 minutes later and I found it out by myself. But I thought maybe someone finds it helpful to know, what the problem was:

 

List items ARE Arrays. But to access the items one has to use the property "text":

 

 

 

function selectLayers(mySelection){
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
  for(i=0;i<mySelection.length;i++){
    if(mySelection[i].text.indexOf("Element 2") > -1){ // Select by Type
        alert(i+" YES");
        }else {
            alert(i+" NO");
            }
       }
}

 

 

Topics

Error or problem, How to, Scripting

Views

31

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

ListItem <=> Array (ExtendScript)

Explorer ,
Aug 06, 2020

Copy link to clipboard

Copied

I'm trying to use a selection from a multiline listbox as arguments in a function, but It does not work.

If I'm testing it with an static array as test-argument everything works fine -  the testing structure tells me that it is an array and tells me "yes" when I ask it if it contains "Element 2" (var selectableTypes as argument instead of myDropdown.selection).

 

But if I send a ListItem it tells me it is an array but "no" at the test afterwards.

Corvin0_1-1596717030511.pngCorvin0_2-1596717041269.png

 

 

And If I add another test asking for array elements 0 and 1, it crashes completely with this error:

Corvin0_0-1596716866557.png

 

Remember, that it told me it IS an array before, but it looks like it is not one at the same time...I'm confused 😉

 

myPanel = new Window ('dialog {orientation:"row"}'); 

var selectableTypes = ["Element 1","Element 2","Element 3"];

// UI ************************************
var myGrp = myPanel.add('group {orientation:"row", alignChildren:"fill"}');
var myDropdown = myGrp.add("listbox", [0,0,200,200], selectableTypes, {scrolling: true, multiselect: true});
var myButton = myGrp.add("button",[0,0,100,20],"Select");
//****************************************

myButton.onClick = function (){selectLayers(myDropdown.selection);}
function selectLayers(mySelection){
alert (mySelection[0]+" and "+mySelection[1]); // This test breaks it with the ListItem!
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
    if(mySelection.indexOf("Element2") > -1){ // Select by Type
        alert(" YES");
        }else {
            alert(" NO");
            }
       }

myPanel.center();
myPanel.show();

 

So, only 10 minutes later and I found it out by myself. But I thought maybe someone finds it helpful to know, what the problem was:

 

List items ARE Arrays. But to access the items one has to use the property "text":

 

 

 

function selectLayers(mySelection){
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
  for(i=0;i<mySelection.length;i++){
    if(mySelection[i].text.indexOf("Element 2") > -1){ // Select by Type
        alert(i+" YES");
        }else {
            alert(i+" NO");
            }
       }
}

 

 

Topics

Error or problem, How to, Scripting

Views

32

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 06, 2020

Copy link to clipboard

Copied

So, only 10 minutes later and I found it out by myself. But I thought maybe someone finds it helpful to know, what the problem was:

 

List items ARE Arrays. But to access the items one has to use the property "text":

 

 

 

function selectLayers(mySelection){
  
 if(mySelection.constructor === Array){ alert ("Is Array");  } else  { alert("Not an Array");} // Ergebnis: Is Array
  
  for(i=0;i<mySelection.length;i++){
    if(mySelection[i].text.indexOf("Element 2") > -1){ // Select by Type
        alert(i+" YES");
        }else {
            alert(i+" NO");
            }
       }
}

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...