Templates API
tpl.remove()
asyncRemoves template elements.
-
Accepts the template name, as a string, as the first argument.
Accepts an optional second argument, which can be one of the following:TypeDescriptionobjectThe template elements whose values match those specified in the object (case-insensitive) or match a regular expression defined in the object will be removed.arrayThe template elements whose indexes match the specified numbers from the array will be removed.numberThe template element whose index corresponds to the specified number will be removed. -
Returns an object with the following properties:
PropertyTypeDescriptionitDOM elementThe block element where the template elements are placed.fieldsarrayAn array of objects that remain after removing template elements with the following properties:PropertyTypeDescriptionitDOM elementThe template element.dataobjectThe data of the current template element.
- It is not necessary to wait for the method to be executed using await if not needed.
Example:
await tpl.remove();
// false
await tpl.remove('tplDoesNotExist');
// null
// Removes all template elements.
await tpl.remove('tplName');
/*
{
it: div[data-tpl="tplName"],
fields: []
}
*/
// Removes the template element at index 0.
await tpl.remove('tplName', 0);
/*
{
it: div[data-tpl="tplName"],
fields: [
{
it: div.field,
data: {name: 'book 2', secondName: 'cat 2'}
}
]
}
*/
// Removes the template elements at indexes 0 and 1.
await tpl.remove('tplName', [0, 1]);
/*
{
it: div[data-tpl="tplName"],
fields: []
}
*/
/*
Removes the template elements where the 'name' property is "book" or "book 2",
and the 'secondName' property matches the specified regular expression.
*/
await tpl.remove('tplName', {name: ['book', 'book 2'], secondName: /2/});
/*
{
it: div[data-tpl="tplName"],
fields: [
{
it: div.field,
data: {name: 'book', secondName: 'cat'}
}
]
}
*/