Browse Source

Add `findType` method in Component

pull/2031/head
Artur Arseniev 7 years ago
parent
commit
79d0b3f9f8
  1. 21
      src/dom_components/model/Component.js

21
src/dom_components/model/Component.js

@ -240,6 +240,27 @@ const Component = Backbone.Model.extend(Styleable).extend(
return result;
},
/**
* Find all inner components by component id.
* The advantage of this method over `find` is that you can use it
* also before rendering the component
* @param {String} id Component id
* @returns {Array<Component>}
* @example
* const allImages = component.findType('image');
* console.log(allImages[0]) // prints the first found component
*/
findType(id) {
const result = [];
const find = components =>
components.forEach(item => {
item.is(id) && result.push(item);
find(item.components());
});
find(this.components());
return result;
},
/**
* Find the closest parent component by query string.
* **ATTENTION**: this method works only with already rendered component

Loading…
Cancel
Save