Thursday 27 February 2014

Knockoutjs arrayIndexOf or indexOf

arrayIndexOf() || indexOf()

Using arrayIndexOf() or indexOf(), find all matched items from an array collection. If items matched then returns true else returns false.

 var arrayIndexOffunction (keyword) {
           try {
               var keyText = keyword.toLowerCase();         
               if (!keyText) {
                   return arrayCollection();
               }
               else {
                   if (arrayCollection().length > 0) {
                       var match = ko.utils.arrayIndexOf(arrayCollection(), function (item){  
                                    return item.Lable.toLowerCase() === keyword.toLowerCase();      
                       });

                       If(match){
                   return true;
                        }
                        else{
                            return false;
                        }
                  }
               }
           }
           catch (ex) {
               //TODO: something..
          }

  };


No comments:

Post a Comment