When you execute a query with the find()
function, it returns a Promise that resolves to a MembershipsQueryResult
object.
This object contains the items that match the query, information about the
query itself, and functions for paging through the query results.
Returns the index of the current results page number.
The currentPage
is a zero-based index of the current page of results.
The page size is defined by the limit()
function, can be retrieved using the pageSize
property, and
navigating through pages is done with the prev()
and
next()
functions.
The currentPage
property returns undefined
if the query returned no results.
let resultPage = results.currentPage; // 0
Returns the items that match the query.
The current page of memberships retrieved by the query.
Note: When no items match the query, the items array is empty.
To paginate your query results, use the MembershipsQueryResult
pagination properties and functions.
import { Permissions, webMethod } from "wix-web-module";
import { members } from "wix-groups-backend";
// Sample memberId value:'2ac55ba-b3cd-457f-2978-617832783d624'
export const getQueryResultItems = webMethod(Permissions.Anyone, () => {
return members
.queryMemberships()
.limit(3)
.find({ memberId: memberId })
.then((results) => {
if (results.items.length > 0) {
return results.items;
} else {
console.log("No items found");
}
})
.catch((error) => {
console.error(error);
});
});
/* items:
* [
* {
* "groupId": "937cd3db-e9be-4980-93c1-a6d767a11050"
* "status": "JOINED"
* "role": "MEMBER"
* },
* {
* "groupId": "7fe8e9e1-d050-4c86-9684-e7f231600a34"
* "status": "PENDING"
* "role": "MEMBER"
* },
* {
* "groupId": "2CD58761-d050-4c86-9684-e7f2316229b3"
* "status": "JOINED"
* "role": "ADMIN"
* }
* ]
*/
let resultLength = results.length; // 20
let resultPageSize = results.pageSize; // 50
Returns the MembershipsQueryBuilder
object used to get the current results.
Use the query
property to create and run a new query by chaining additional MembershipsQueryBuilder functions to it.
let resultQuery = results.query;
Returns the total number of items that match the query.
The totalCount
returns the total number of items that match the query,
not just the number of items in the current page.
let resultCount = results.totalCount; // 150