Hi,
I have been using your awesome libraries to create a javascript based search on engine for a site I am working on.
I have been noticing some odd behaviour when iterating through an observablearray.
So first, some context. The scripts I have written are used to
- Populate a search screen with items and filter options returned from ASP repeaters
- Filter search results
- Access items from this page or controls related to it
One odd piece of behaviour I have noticed is that when selecting a filter option (which is bound to a function within it's knockout object), the script is slow to loop through the observablearray containing all of the results (Usually 1000ish items). What happens during this process is that during each loop, the script will check the item against all of the filters that have been selected by the user, and will either hide or show this item depending on the outcome. What's weird is that the first time this function is invoked by the user, it is rather slow, but after that, the functionality becomes a lot faster, almost instantaneous to carry out.
Pseudocode: for (i = 0; i < self.Items().length; i++) {
var currItem = self.Items()[i];
currItem.ShowOnResults(true);
//Carries out checks against all filter options
//Sets ShowOnResults to false if it fails one of the filter arguments
}
In summary, is there a way I could potentially speed this process up, am I doing something wrong or is it a matter of I'm putting too much pressure on the knockout libaries?
Thanks.