Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

How to use a promise value for an array filter method?

$
0
0

@KioMio wrote:

I need to return the boolean result of a file readAsText promise to an array filter method. The promise returns the correct value, based on the inputs. But I do not know how to get a value for the “return” function. First is the called function, followed by the array filter code segment.

phraseFound(path: string, phrase: string) {
let panelMediaFile = ‘panelMedia_’ + this.global.langAbbv + ‘.json’;

return  this.file.readAsText(this.global.fileSystem.int + path, panelMediaFile).then((jsonStr) => {
          let found = (jsonStr.toLowerCase().indexOf(phrase) == -1) ? false : true;
          return found;   //found = TRUE
        }).catch((err) => { this.global.showError('t10', err); });

}

    filteredItems = filteredItems.filter( item => {
      let tapaSrcPath = this.global.path.titles + item.titleURI + '/tapaSrc/';
      let found = this.phraseFound(tapaSrcPath, searchTermsPhrase)
        .then(found => {
          return found;   //found = TRUE
        });
      return found;   //found = promise object
    });

Thank you in advance!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>