In AnQi CMS,archiveFiltersAn interface is a very practical feature that allows us to obtain the filtering conditions of a specific document model, thereby helping users to implement flexible content filtering on the front-end page.For example, on a product display page, we may need to filter based on the product's attributes such as 'color', 'size', or 'brand'.
So, if a document model is exactly not configured with any selectable custom fields, the call toarchiveFiltersWhat will the interface return? The answer is actually very simple: it will return a successful response, but the data part ("datawill be an empty array[].
This conforms to the good practice of most API designs. When the requested dataset does not exist or is empty, the API usually does not return an error status code (such as-1),unless the request parameters themselves are incorrect (such asmoduleIddoes not exist). Instead, it will return a representation of success(code: 0But the data structure of the empty result set.This means that in AnQi CMS, the system explicitly informs you that you have successfully queried the filtering conditions under the model, but there are currently no filtering fields that meet the conditions.
This is crucial for frontend developers to understand. When you callarchiveFiltersWhen interfacing, proper handling is requireddataBe prepared for the field to be an empty array. You can checkdataThe length of the array is zero to determine whether the current model provides a filtering function.If empty, the corresponding filtering area on the front-end interface does not need to be rendered, or it can display a friendly prompt, such as 'No filtering conditions available'.This can avoid program errors caused by attempting to iterate over a non-existent or undefined filter list, and also optimize the user experience.
If you want to add a filtering feature to a document model, so that it can bearchiveFiltersThe interface returns meaningful data, you need to configure the document model in the Anqi CMS backend.The specific steps usually involve entering "Document Model ManagementarchiveFiltersIt can only be returned by the interface. Once set and saved, the data of these fields will bearchiveFiltersThe interface identifies and returns, including the screening name, field calling name, and the specific screening parameter list (such as Beijing, Shanghai, etc.).
In short,archiveFiltersThe interface returns an empty array when there are no filterable custom fields.[]This is a normal response behavior, developers should handle it according todatawhether the array is empty to flexibly display or hide the filtering function.
Frequently Asked Questions (FAQ)
Q1:archiveFiltersThe interface returns an empty array[]Is it an error?A1: No.This indicates that the interface call was successful, but the current document model does not have any custom fields configured for filtering.dataThe array is empty.
Q2: How do I know if a document model is configured with filterable custom fields?A2: The most direct method is to callarchiveFiltersthe interface and check the returned data.dataarray. ifdataThe array is not empty, which means the model contains filterable fields.You can also check the custom field settings of the specific model in the "Document Model Management
Q3: If I need a filter function, how can I makearchiveFiltersthe interface return data?A3: You need to log in to the AnQi CMS backend, find the corresponding document model, and enter the custom field management page.In there, enable the 'filterable' option for custom fields that you want to use as filter conditions (for example, text, radio, checkbox field types).archiveFiltersThe interface will return these configured filter conditions.