During the development and content management of AnQi CMS, we often need to handle document filtering and display.archiveFiltersThe interface is designed for this, it provides the ability to dynamically obtain filtering conditions. Understanding the returned data innameandfield_namefields is crucial for building flexible front-end filtering functions.
name: User-friendly filter condition display name
When we go througharchiveFiltersThe data returned when the document filter condition is retrieved through the interface will include anamefield. Thisnamefield represents the filter conditiondisplay nameorUser-friendly nameIt is presented in human-readable language (usually Chinese), and its main function is to display clear and intuitive filtering options on the website front end.
For example, in the example data returned by the interface, we can seenameFor "city" and "education". These are the labels you usually see on a page, used for user selection. You cannameUnderstand that you define the Chinese name or description of a custom field in the AnQi CMS background, which is directly facing the end user and aims to provide a good interactive experience.
field_name: The internal filter field call name
withnameis accompanied byfield_name. It plays a completely different role in terms of function.field_namerepresents the filter conditions oftechnical identifierorAPI call nameIt is usually a short English word or pinyin, used to uniquely identify a filtering condition in backend logic and API requests.
Thisfield_nameIt is the system name defined for the field when custom field settings are made in the Anqi CMS backend, which is used internally to process data and construct queries. For example, whennameWhen it is 'city', its correspondingfield_namemay be 'city'; whennameit is 'education', itsfield_namemay be 'certificate'.
field_nameThe core function lies in its uniqueness and stability. When the user selects one in the front-end interface,nameWhen the filtering condition for "city" is set to "Beijing", your front-end code will use its correspondingfield_name"city" as a parameter to pass toarchiveListetc interfaces. For example, a request/api/archive/list?moduleId=1&city=北京The backend can then filterfield_name“city” accurately to find all documents where the city is “Beijing”.
Additionally, when obtaining document details,archiveDetailWhen a document contains custom fields, these fields are also present asextrakeys in the object. For example,field_namemay appear in the objectextra, here is theauthor: { name: '作者', value: 'AnqiCMS', default: '' }.authorIt is the custom fieldfield_name.
namewithfield_namecollaboration
In short,nameis provided for users to view, convenient for users to understand and operate; andfield_nameIt is provided for the program to ensure the accuracy of API calls and data processing.This separation design makes the website have a good user experience while also maintaining the clarity and efficiency of the backend data logic.archiveFiltersThe interface retrieves these two, allowing developers to dynamically build various filters without hardcoding the conditions, thereby greatly enhancing the flexibility and maintainability of the website.
Frequently Asked Questions (FAQ)
1. Why do we need both fields to existnameandfield_nameWhat are these fields for?
This design aims to separate the presentation layer from the data processing layer.nameProvide a user-friendly interface display, allowing users to easily understand and select filtering conditions; andfield_nameIt serves as the unique identifier for internal system and API interactions, ensuring the accuracy and stability of data processing. You cannameconsider as a label,field_nameconsider as the "code" behind the label.
2.field_nameCan it be changed arbitrarily? What impact will it have after the change?
It is usually not recommended to change arbitrarilyfield_name. Becausefield_nameOnce set, it may be referenced in multiple places, such as inarchiveListIn the interface query parameters orarchiveDetailreturnedextrafield as the key name. Frequent modifications may lead to dependencies on thisfield_nameThe front-end function or third-party integration has failed, so it should be defined cautiously when creating custom fields.
3. How to utilize in the front-end pagearchiveFiltersto build filtering functions with the returned data?
You can traversearchiveFiltersThe interface returnsdatathe array, using each item'snameas the display text for the filter button or dropdown menu. After the user selects a filter condition, get the correspondingfield_nameanditemsselected item in the array.label(or actual value), thenfield_name=labelcall as a query parameterarchiveListto get the filtered document list. This can realize dynamic and flexible filtering functions.