Skip to main content
Known Participant
June 23, 2013
Question

If argument with a tiny indexOf problem

  • June 23, 2013
  • 1 reply
  • 506 views

These values get through the argument:

may

may/jun

and get separated

This does not:

may/jun/jul

What am I doing wrong here?

function Blomstring(ar){

var newAr = [];

var newData = [];

var findEl = false;

var el = "";

for(var i=0; i<ar.length; i++){

findEl = false;

el = ar['Blomstring'];

if(el == '' || el.indexOf('/')!=-1){

          continue;

}

          for(var j=0; j<newAr.length; j++){

                    if(newAr==el){

                    findEl = true;

                    }

          }

if(findEl==false){

newAr.push(el);

}}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
June 23, 2013

What are you trying to do?

Rhov23Author
Known Participant
June 23, 2013

To make it short:

I have list1 that is populated with plant names.

Then I have list2 which is connected to the function shown above, that will filter plants that that bloom in specific months.

My large xml file has however plants that bloom not only in may, but may/jun, may/jun/jul etc.

The if argument in the code shown above makes may/june, show up correctly as both may and jun in filter list2, and it filters list1 correctly. But may/jun/jul, or jul, or jul/aug doesn't show in the filter list2

The problem arises when i have 2  "/" like in jun/jul/aug

.

if(el == '' || el.indexOf('/')!=-1){

          continue;

Here is the full function:

function Blomstring(ar){

var newAr = [];

var newData = [];

var findEl = false;

var el = "";

for(var i=0; i<ar.length; i++){

findEl = false;

el = ar['Blomstring'];

if(el == '' || el.indexOf('/')!=-1){

          continue;

}

          for(var j=0; j<newAr.length; j++){

                    if(newAr==el){

                    findEl = true;

                    }

          }

if(findEl==false){

newAr.push(el);

}}

newAr.sort();

          for(var k=0; k<newAr.length; k++){

          newData.push({'label':newAr});

          }

list2.dataProvider = new DataProvider(newData);

}

Blomstring(a);

list2.addEventListener(Event.CHANGE, change4);

function change4(event:Event):void {

searchInput.text = "";

filterBlomstring(list2.selectedItem.label,a);

//Deselects the other filter lists

list3.selectedIndex = -1;

list4.selectedIndex = -1;

//

}

function filterBlomstring(filter,ar){

var newData = [];

var newAr = [];

var el = "";

var findEl = false;

          for(var j=0; j<ar.length; j++){

                    el = ar['Blomstring'];

                    if(el.indexOf(filter) != -1){

                              newAr.push(ar['Botanisk_navn']+'\n'+"-" + ar['Norsk_navn']);

                    }

          }

newAr.sort();

          for(var k=0; k<newAr.length; k++){

          newData.push({'label':newAr});

          }

//listAr is what is being populated in "list"

listAr = newAr;

list.dataProvider = new DataProvider(newData);

firstRow();

}

Ned Murphy
Legend
June 23, 2013

I'm still not following what your code is trying to do, but if you want to extract the stuff that lives around the slashes, then you can just use the String.split() method to create an array of the months involves in the string.