From 8b952bb9d687fc5f75b2f50bb37f437cdbeeaa85 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 27 Jan 2021 21:47:11 +0100 Subject: [PATCH] Add removeAttributes method to Component --- src/dom_components/model/Component.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index c927b4b91..45d63b45a 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -430,6 +430,22 @@ const Component = Backbone.Model.extend(Styleable).extend( ); }, + /** + * Remove attributes from the component + * @param {String|Array} attrs Array of attributes to remove + * @param {Object} options Options for the model update + * @return {this} + * @example + * component.removeAttributes('some-attr'); + * component.removeAttributes(['some-attr1', 'some-attr2']); + */ + removeAttributes(attrs = [], opts = {}) { + const attrArr = Array.isArray(attrs) ? attrs : [attrs]; + const compAttr = this.getAttributes(); + attrArr.map(i => delete compAttr[i]); + return this.setAttributes(compAttr, opts); + }, + /** * Get the style of the component * @return {Object}