I am currently working with a model for my view.
This model consists of an array of objects:
var arr = { "12345qwery": { prop1: "value", prop2: "value" } } // consisting of 500 items
When filtering this array today, I use the following method:
arr = $filter('filter')(arr, filterTerm); // resulting in 4 items
However, I have noticed that after applying the filter once, if I apply it again, I only get back 4 items instead of the original 500.
To address this issue, I have been storing the original array in a temporary object and reverting back to it whenever the user changes the filter criteria before reapplying the filter.
Managing multiple filters has become quite cumbersome as I now have to restore the original data before each filter operation... it's turning into a mess :)
Is there a more efficient (angular) way to handle JavaScript filtering in this scenario?
UPDATE
I have created a plunker to better illustrate the issue:
https://plnkr.co/edit/99b02UtUfPeM3wl4IiX6?p=preview
As you can see, I am loading markers with associated objects and attempting to filter them using a text field.
However, I seem to be encountering errors consistently.
Am I missing something here?
In order to overcome this challenge and implement a smoother filtering process, I opted to revert to handling it through code while keeping a copy of the original array post each filter application. However, this solution is intricate and I would prefer a more seamless angular approach.
BOUNTY UPDATE
I have resorted to filtering objects within the js
code due to difficulties in finding a standard angular method to filter markers within this directive.
Consequently, I perform filtering using code and always maintain a backup copy beforehand.
I require assistance with filtering marker objects within this directive through a conventional angular methodology.
The Plunker showcases this directive, but I am uncertain about how to effectively implement the filter.