Templates API
tpl.pos()
asyncComputes the index of the template element, whether the passed element is the template element itself or one of its descendants, along with the data of the template containing this element.
- Accepts a single argument as a DOM element.
-
Returns an object with the following properties:
PropertyTypeDescriptiontplDOM elementA block containing template elements.namestringThe name of the template in which the passed element is placed.fieldDOM elementThe template element itself, even if a descendant is passed.idxnumberThe index of the template element itself, even if a descendant is passed.
Example:
await tpl.pos();
// false
await tpl.pos(null);
await tpl.pos($('body'));
// null
await tpl.pos($('[data-tpl="tplName"] .book'));
/*
{
tpl: div[data-tpl="tplName"],
name: 'tplName',
field: div.field,
idx: 0
}
*/
await tpl.pos($('[data-tpl="tplName"] > * ? 1'));
/*
{
tpl: div[data-tpl="tplName"],
name: 'tplName',
field: div.field,
idx: 1
}
*/