knockout js filter array

Knockout js Filter an observable Array


Array filter is availing an observable-array and returns true if array of items are match otherwise returns false. 

var filterSelections = ko.computed(function (Text) {
           try {
               var filterText = Text.toLowerCase();         
               if (!filterText) {
                   return selectionList();
               }
               else {
                   if (selectionList().length > 0) {
                       return ko.utils.arrayFilter(selectionList(), function (item) {
                           if (item.SelectionLabel.toLowerCase().indexOf(filterText) > -1 || item.SelectionDescription.toLowerCase().indexOf(filterText) > -1) {
                               return true;
                           }
                           else {
                              return false;
                           }
                       });
                   }
               }
           }
           catch (ex) {
               logExceptions(ex);
           }
 });

It might help you for more detail 
knockoutjs filter observable array
ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.