isMember
Return if a record belongs to a query.
queryLogic.isMember(query, record)
Used to tell if the query
contains the instance object record
.
import {QueryLogic} from "can";
const queryLogic = new QueryLogic();
const checkMember = queryLogic.isMember(
{filter: {playerId: 5}},
{id: 5, type: "3pt", playerId: 5, gameId: 7}
);
console.log( checkMember ); //-> true
Use index to know where to insert the record
into a list of
records.
isMember
ignores the query's page
values and will return true
if the query's filter
matches
the data. For example, "Zebra" might be the last record if all animals were sorted by name. However,
isMember
will still return true:
import {QueryLogic} from "can";
const animalQueryLogic = new QueryLogic();
const checkAnimal = animalQueryLogic.isMember(
{sort: "name", page: {start: 0, end: 0}},
{id: 1, name: "Zebra"}
);
console.log( checkAnimal ); //-> true
This is a limitation of QueryLogic when used with paginated sets of data.
Parameters
- set
{Query}
:A set.
- record
{Object}
:A JavaScript object of key-value pairs.
Returns
{Boolean}
:
Returns true
if record
belongs in set
and
false
it not.
Dealing with paginated sets
If you have paginated data, and you would like to build a real-time application that knows if some newly created data belongs within that paginated set, you will need to build a custom real time can-connect behavior.
If you are encountering this problem, please post a question on the forums and Justin will detail how to solve this problem.