Accordion Library: Content Parameter with Examples
Category: ExamplesThe Accordion library can create nested collapsible panels and supports multiple data formats.
Introduction
When using the Accordion
instance, the content
parameter can accept multiple types of data. Upon a successful request, it receives branch data such as label
, tips
, badge
, and content
. The content
field in the branch data may not always be a string or a DOM node—it could also be an object or an array. So how should we handle content
when it is an object or array?
content as a Node
When content
is a DOM node, it will be fully appended into the contEl
container.
content as an Object
When content
is a plain object, it will be treated as renderable data. In this case, you need to use a template string (tplStr
) and a template engine (tplEng
) to convert it into a string.
content as an Array
When content
is an array, it will also be treated as data and needs to be rendered using tplStr
and tplEng
as well.
content as a Special Object
When content
is an object, it is normally treated as data to be rendered (requires tplStr
and tplEng
). However, if the object includes the property REQRETRY: true
, it will not be rendered directly but instead used to initiate another data request.