filterMembers
Filter data using a query.
queryLogic.filterMembers(a, [b,] bData)
Filters the a
query's records from another super set query's records.
import {QueryLogic} from "can";
const queryLogic = new QueryLogic();
const filter = queryLogic.filterMembers(
{filter: {type: "dog"}},
{filter: {type: ["dog", "cat"]}},
[{id: 1, type:"cat"},
{id: 2, type: "dog"},
{id: 3, type: "dog"},
{id: 4, type: "zebra"}]
);
console.log( filter ); //-> [{id: 2, type: "dog"},{id: 3, type: "dog"}]
The super set b
argument is optional. It defaults to assuming the universal query. For example,
the following still works:
import {QueryLogic} from "can";
const queryLogic = new QueryLogic();
const filter = queryLogic.filterMembers(
{filter: {type: "dog"}},
[{id: 1, type:"cat"},
{id: 2, type: "dog"},
{id: 3, type: "dog"},
{id: 4, type: "zebra"}]
);
console.log( filter ); //-> [{id: 2, type: "dog"},{id: 3, type: "dog"}]
The super set b
argument is important when pagination is present:
import {QueryLogic} from "can";
const queryLogic = new QueryLogic();
const filter = queryLogic.filterMembers(
{page: {start: 11, end: 12}},
{page: {start: 10, end: 13}},
[{id: 1, type:"cat"},
{id: 2, type: "dog"},
{id: 3, type: "dog"},
{id: 4, type: "zebra"}]
);
console.log( filter ); //-> [{id: 2, type: "dog"},{id: 3, type: "dog"}]
records will be returned sorted by the query's sort
property.
Parameters
- a
{Query}
:The query whose data will be returned.
- b
{Query}
:An optional superset of query
a
. If only two arguments are provided, the universal set is used. - bData
{Array<Object>}
:The data in query
b
.
Returns
{Array<Object>}
:
The data in query a
.