How to interpret the `items` array in the filtering conditions API, used to build the front-end filter?

Calendar 👁️ 67

In modern web design, the content filtering feature has become an important component for improving user experience and content discoverability.A well-designed filter can help users quickly locate the information they are interested in, whether it is products, articles, or any other form of content.For AnQi CMS, the API for its provided filtering conditions (/api/archive/filtersIt is the foundation for building such front-end filtering functions. Especially in the response data,itemsthe array, which is the key to understanding and implementing dynamic filtering.

the foundation of filtering conditions:archive/filtersAPI

Of Security CMSarchive/filtersAn interface that provides all available filtering conditions under a specified content model for the front-end. When you need to build a filter for a module (such as an article module, product module), you just need to call this API and pass in the correspondingmoduleIdFor example,GET /api/archive/filters?moduleId=1It will return all the filter configurations of the article module.

The response data structure of this API is clear, with the outermost layer beingdatais an array, each object in the array represents an independent filter. Each filter object contains three key attributes:name/field_nameanditems.

  • nameThis is the name displayed on the user interface of the filter, such as 'City' or 'Education', for easy understanding.
  • field_nameThis attribute is crucial, as it represents the field name that needs to be used as a URL parameter when performing content queries. For example, ifnameis 'City', thenfield_namemay be justcity.
  • itemsThis is the focus of our day, it is an array that contains all the specific items available under the current filter.

In-depth analysisitemsarray

itemsAn array is a collection of specific options within each filter. Each element of the array is an independent object, usually containinglabelandtotalThese two properties together constitute the complete information of each option in the front-end filter.

  • label: Display text of the filter option labelThe value is the option name that users see directly on the frontend interface. For example, in a 'City' filter,itemsin the array,labelIt could be "Beijing", "Shanghai", "Chongqing", etc. It is a friendly name for the filter options, directly presented to the user. When building the front-end interface, you will use theselabelCreate dropdown menus, checkboxes, radio buttons, or tag clouds as filter controls.

  • total: Number of items under the current option totalThe property indicates the current filter option (i.e.labelUnderneath, the total number of documents matched by AnQi CMS. This number has a high practical value on the frontend interface.For example, you can display "Beijing (123)" to the user, directly telling them that after selecting "Beijing" as a condition, they will find 123 relevant articles.

    Furthermore,totalThe value can still help you optimize the user experience:

    • Smart disable/hide:If an option'stotalFor 0, it means that there is no content in the current database that meets the condition. You can disable or hide this option on the front-end to avoid users feeling confused when they click and find no content.
    • Visual feedback:The existence of numbers can provide users with an expectation, allowing them to understand the number of possible results before clicking.

Practical steps for building a frontend filter

UnderstooditemsAfter the structure of the array, we can proceed to apply it to the construction of the frontend filter:

  1. Get filtered data:Firstly, when the page loads, by making an asynchronous request to call/api/archive/filtersAn interface carrying the respectivemoduleId. This will retrieve all available filtering conditions of the module and itsitemsarray.
  2. Parsing and rendering:After receiving the response data, traversedataArray. For each filter object, extract itsnametitle as the filter, extractfield_namename as the parameter for subsequent queries. Next, traverse theitemsarray, using eachitemoflabelRender the front-end filtering options (for example, create a series of buttons or dropdown menu items). At the same time, you can alsototaldisplay the value inlabeladjacent to the document count, or based ontotalWhether 0 determines the availability of the option.
  3. Build query parameters:When a user selects one or more filter options on the front end, you need to dynamically construct query parameters based on their choices. For example, if the user infield_nameWithcityhas selected the filterlabelFor the option of 'Beijing', you need tocity=北京This parameter should be added to your content list API request. If the Anqi CMS supports multiple selections, multiple selection values are usually separated by commas (such ascity=北京,上海), for more details please refer to/api/archive/listDescription of custom filtering parameters in the interface.
  4. Initiate a content list request:Send the constructed filtering parameters along with other parameters such as pagination, sorting, and so on./api/archive/listThe interface will return a list of documents that meet all the filtering conditions for front-end display.
  5. Update the filter status (optional):In some complex filtering scenarios, after the user selects a filter condition, you may need to call againarchive/filtersInterface

Related articles

What do the `name` and `field_name` in the `archiveFilters` interface represent?

During the development and content management process of Anqi CMS, we often need to handle document filtering and display.The `archiveFilters` interface was born for this purpose, it provides the ability to dynamically obtain filtering conditions.Understand the `name` and `field_name` fields in the returned data, which are crucial for building flexible and versatile front-end filtering functions.

2025-11-09

In AnQi CMS, what is the role of the `moduleId` parameter in the `archiveFilters` interface?

When using AnQiCMS to build a website, we often need to provide flexible filtering functions for different types of content so that visitors can quickly find the information they need according to their needs.The `archiveFilters` interface was born for this purpose, it can help us get the document filtering conditions.And in this interface, the `moduleId` parameter plays a crucial role.### `archiveFilters` interface's `moduleId`

2025-11-09

How to get the parameter filter condition list of a specified document model?

In website operation, providing users with a convenient content filtering function can significantly improve user experience and content discovery efficiency.The Anqi CMS provides powerful interfaces, allowing us to flexibly obtain and utilize these filtering conditions.Today, let's discuss how to get the parameter filtering condition list of a specified document model in Anqi CMS. ### The Importance of Understanding Filtering Criteria Imagine if your website has many products or articles, and users want to search based on dimensions such as "city", "education", or "product type".

2025-11-09

How to optimize the navigation experience of the previous and next documents through the `archivePrev` and `archiveNext` interfaces?

Today, with the increasing refinement of content management, every detail of a website may affect the reading experience of users.Among them, the navigation between the previous and next documents, as an important part of guiding users to continuously explore the website content, should not be overlooked in terms of convenience and fluidity.AnQiCMS (AnQiCMS) knows this and provides the powerful and intuitive interfaces `archivePrev` and `archiveNext` to help us easily implement and optimize this feature.###

2025-11-09

Why does the `total` field often display as 0 in the `archiveFilters` returned data? What is its real purpose?

When using AnQi CMS for website content management, we often deal with various API interfaces.Among them, the `archiveFilters` interface is an important tool for obtaining document filtering conditions.Many users notice that when using this interface, the `total` field in the `items` list of the returned data always displays as `0` for each filter option (such as `Beijing` and `Shanghai` under `City`).This may be confusing: Since it's a 'quantity', why is it `0`? This

2025-11-09

How to apply the filtering conditions obtained from the `archiveFilters` to the `archiveList` interface for document filtering?

In AnQi CMS, implementing the dynamic filtering function of documents is a key step to improve the user experience of the website.This usually involves close collaboration between two core interfaces: `archiveFilters` is used to obtain available filtering conditions, while `archiveList` is responsible for retrieving and displaying the corresponding document list based on these conditions.A deep understanding of how they work together can help us build flexible and user-friendly content filtering mechanisms for websites.### Understanding the Filtering Mechanism: From Definition to Discovery Imagine that your website has published a large number of articles

2025-11-09

How to configure custom fields in Anqi CMS so that they can be used as filter conditions?

In AnQi CMS, configuring custom fields as filter conditions is a very practical feature to make your website content more dynamic and interactive.It can help users quickly find the content they need based on specific attributes, thereby significantly improving the user experience of the website.Next, let's learn how to implement this feature in AnQi CMS. ### Custom Field: The "Alive" Tag of Content Firstly, we need to understand what a custom field is.

2025-11-09

What is the difference between the interface for getting document parameters (`archiveParams`) and the interface for getting document parameter filtering conditions (`archiveFilters`)?

When using AnQiCMS for website content management, we often need to deal with document-related API interfaces.Among them, the interface names `archiveParams` and `archiveFilters` sound similar at first glance, and they are both related to Understanding the differences between them can help us develop and manage websites more efficiently.

2025-11-09