Autosuggestion not working with canjs

I am trying to create an automatic offer item manually. I am using canjs for this prupose.

The following code I have tried so far:

list.filter( function( item, index, list ) { if(item.includes(searchText) && searchText != ''){ //css hide and show classes for match } else{ // css show for unmatched results } }) 

In the above code, I ran into two problems:

  • include does not work in all browsers. To do this, I tried the match,
    contains a substring, but they could not help me.

  • includes work in chrome, but when I entered the line, the substring is not contained in the last element of the list, this will not be because the filter will continue to search from all elements.

Is there any mistake I am making?

I want it to run in all browsers.

Thanks.

+6
source share
1 answer

String.prototype.includes() with one argument is equivalent to using the operators !!~ before String.prototype.indexOf() , and the last in all browsers. So your test string might be like this:

if(!!~item.indexOf(searchText) && searchText !== ''){

0
source

Source: https://habr.com/ru/post/988126/


All Articles