From 1db1415548f15ee65f857ab718d25a17001f8d75 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 7 Dec 2018 15:47:40 +0100 Subject: [PATCH] Add `index` method to Component API --- src/dom_components/model/Component.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index 26f808325..2029cc75d 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -188,6 +188,15 @@ const Component = Backbone.Model.extend(Styleable).extend( return !!(this.get('type') == type); }, + /** + * Get the index of the component in the parent collection. + * @return {Number} + */ + index() { + const { collection } = this; + return collection && collection.indexOf(this); + }, + /** * Find inner components by query string. * **ATTENTION**: this method works only with already rendered component