How to display the `extra` object, how to access its `name` and `value`?

Calendar 👁️ 75

When using AnQiCMS to manage website content, the flexibility of the document model custom fields is one of its highlights.These custom fields allow us to add unique properties for different types of documents (such as articles, products, etc.), greatly enriching the content dimension.extrain the object.

UnderstandingextraThe structure of the object and how to extract the required information is crucial for developers or content managers.extraThe design of the object is very intuitive, it is essentially a collection of key-value pairs, where each key (key) corresponds to the 'field_name' of the custom field in the document model.This call name is specified when we set up custom fields in the background, it is usually a string in English, convenient for program recognition and access.

When we go througharchive/detailorarchive/listWhen this interface retrieves document data, the JSON structure returned will contain onedatafield, andextrathe object is located atdataThe same level of field. For example, in a document detail response, you might see a similar structure snippet:

"extra": {
  "author": {
    "name": "作者",
    "value": "AnqiCMS",
    "default": ""
  },
  "certificate": {
    "name": "学历",
    "value": null,
    "default": null
  },
  "city": {
    "name": "城市",
    "value": "北京\n上海\n重庆\n广州\n天津",
    "default": "北京\n上海\n重庆\n广州\n天津"
  }
}

From this example, we can clearly see that,extraIt includes multiple custom field objects, such asauthor/certificateandcityEach custom field object also includes three core attributes:

  • nameThis is the display name of the custom field, which is the Chinese name we see on the backend management interface (for example, "authorThis property is mainly used for front-end display, allowing users to intuitively understand the meaning of the field.
  • value: This is the actual value of the custom field entered or stored. It represents the specific content entered by the user for this particular document. If the field has not been filled in, or its value is empty,valueMay be displayed asnullOr an empty string.
  • defaultThis is the default value of the custom field. If the field is not explicitly assigned a value when creating the document, it will use the value defined here.

To accessextrafield of the object with specific customnameandvalueThe process is very direct. First, you need to get toextraThe object itself. Assuming we have received the complete document data through an API request and stored it in a variable namedresponse. Then,extrathe object can be accessed byresponse.data.extra.

Next, if you want to get the name of the custom field named "author" (by calling namedauthor), you can do this:

  • Get the field name:response.data.extra.author.nameThis will return “author”.
  • Get field value:response.data.extra.author.valueThis will return “AnqiCMS”.

Similarly, for the field “education” (namedcertificate), you can access byresponse.data.extra.certificate.nameObtain the "education level" and passresponse.data.extra.certificate.valueGet its current value (in this example it isnull), indicating not filled out. Forcity.response.data.extra.city.valueIt will return a string containing multiple city names, indicating that the field may be set to a multi-select or multi-line text type.

This structure design makes the expansion of custom fields extremely flexible. No matter how many custom fields you add to the document model, they will always be presented in this unified and easy-to-parse format.extraIn the object. This not only facilitates the dynamic rendering of the front-end page, but also provides great convenience for subsequent data processing and business logic implementation.

It is worth mentioning that Anqi CMS also providesarchive/paramsan interface that can be used to obtain the definition information of all custom fields under a document model (or a specific document), including theirname/field_name/typeetc. althougharchive/paramsThe interface returns the "blueprint" of the field, andextraThe field directly provides the filled 'content', but combining them helps us fully understand and utilize the custom field function. For example, when building a form or list header, you can first go througharchive/paramsGet all possible field names and types, then according toextrafill in the content with the actual values.

In summary,extraThe object is a powerful manifestation of AnQi CMS in content organization, it presents the custom fields in the document model in a structured and accessible way, providing great convenience for content operation and development work.Mastering its usage will allow you to manage and utilize the website's various content resources more efficiently.


Frequently Asked Questions (FAQ)

1. If the custom field is not filled in,extraWithin the objectvaluewhat will be displayed?If a custom field is not filled in,extraitsvalueproperty will usually be displayed asnullor an empty string""It depends on the field type and the storage method behind the scenes. In some cases, if a field has not been set at all, it may not even appear.extraIn an object, it is best to check for null values or the existence of properties when processing.

2.extraIs the order of fields in an object fixed? extraAn object itself is a collection of key-value pairs, the order of the internal fields is typically not guaranteed to be fixed, depending on the programming language and the implementation of the JSON parser. If you need fields in a specific order, it is usually recommended to do so in the frontend according tonameorfield_nameSort properties or extract as needed. If you want to retrieve all custom fields while maintaining the order in which they were defined in the background, consider usingarchive/paramsthe interface, which is set in thesorted=trueit will return a field array in the order defined.

3. How to iterate over an object in a front-end page.extraand display all custom fields?In the front end (for example using JavaScript), you can usefor...inloop orObject.keys()/Object.values()/Object.entries()methods to traverseextraobjects. For example, usingObject.entries(response.data.extra)It will return an array containing all custom field key-value pairs, you can iterate over this array, and then process each[key, item]throughitem.nameto get the display name,item.valueGet the field value to dynamically display this custom information on the page.

Related articles

What detailed information will the nested `category` object return?

When we explore the mysteries of content in AnQi CMS, we often need to obtain detailed information about the documents.The `archiveDetail` interface provides us with rich document data, and the nested `category` object is a frequently overlooked but extremely important repository of information.It is not just a simple classification ID, but a complete entity containing all the metadata of the classification, which provides great convenience for us to deeply understand the context of the document and to carry out refined content display.

2025-11-09

If the document is a product type, how can you get its `price` (price) and `stock` (stock) information?

In Anqi CMS, if you are managing documents of product types and need to obtain specific price (`price`) and stock (`stock`) information for these products, it is actually very direct and convenient.The design of AnQi CMS considers such needs, making these key data as one of the core attributes of the document, you can easily obtain them through several core interfaces.### Get the price and stock information of a single product document When you need to view the price and stock of a specific product, AnQi CMS provides the `archiveDetail` interface

2025-11-09

The value of the `status` field in the document details, for example 1, specifically indicates which display status the document has?

When using AnQi CMS to manage website content, you may encounter various technical parameters, one of which seems simple but is crucial is the `status` field in the document details.It acts like a 'switch' for the content, quietly controlling whether your article, product, or other information can be seen by visitors. Then, what does this `status` field specifically represent?In simple terms, it is an integer value used to mark the current display state of the document.

2025-11-09

Is the `created_time` and `updated_time` field of the document in Unix timestamp, how to perform time format conversion?

In AnQiCMS (AnQiCMS), when you obtain various information such as documents, categories, attachments, and users through the API interface, you will find that fields like `created_time` (creation time) and `updated_time` (update time) are usually presented in integer form.This is indeed the Unix timestamp format commonly used by many systems, including AnQiCMS.### What is Unix timestamp? Unix timestamp, also known as POSIX time or Epoch time, is a way to represent time

2025-11-09

How to get the value of a specific custom field (such as "author") through the `extra` field?

In Anqi CMS, the custom fields of documents are a reflection of its powerful flexibility, allowing us to add various unique attributes to content, thereby enabling more precise management and display of information.But for many developers and operations personnel, how to accurately obtain the values of these custom fields through the API is often a clear issue.Don't worry, Anqi CMS provides clear paths in API design, through the `extra` field, you can easily handle these additional data.### Understand the `extra` field

2025-11-09

What does it mean if an error code 1001 or 1002 occurs when getting the document details, and how to solve it?

When using AnQi CMS for website content management and development, we often use API interfaces to obtain various data, among which obtaining document details (`/api/archive/detail`) is very commonly used.When you call this interface, if you encounter system return codes 1001 or 1002, it usually indicates that the request was not successfully processed and a specific reason is given.Understanding the meaning and solutions of these error codes can help us more efficiently troubleshoot problems and ensure the normal display of website content.### Error Code 1001

2025-11-09

Does the document detail interface directly provide the detailed content of the document's category (`category.content`)?

When using AnQi CMS for website development or content integration, it is often necessary to obtain documents and their related information.One of the common questions is: When getting the details of a document, can we also get the detailed content of the category to which the document belongs, especially fields like `category.content`?According to the documents provided by AnQi CMS, we can clearly find the answer.To be direct, **yes, the AnQi CMS document detail interface (`/api/archive/detail`) indeed provides detailed content of the document's category

2025-11-09

How to ensure the uniqueness of document URL alias queries to avoid ambiguity?

When using AnQi CMS for content management, URL aliases (also known as URL Tokens) are a key component for building user-friendly and SEO-optimized websites.It not only makes your page address more readable, but also helps search engines better understand the content topic.However, it is particularly important to ensure the uniqueness of the document when querying through these URL aliases, otherwise it may cause the system to identify confusion, users to access incorrect pages, and even affect the SEO performance of the website.

2025-11-09