Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

If argument with a tiny indexOf problem

New Here ,
Jun 23, 2013 Jun 23, 2013

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);

}}

TOPICS
ActionScript
488
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2013 Jun 23, 2013

What are you trying to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 23, 2013 Jun 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

filtering_problem.jpg.

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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2013 Jun 23, 2013
LATEST

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.

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