Browse Source

Add __innerHTML method to Component

pull/3692/head
Artur Arseniev 5 years ago
parent
commit
75be5144a9
  1. 13
      src/dom_components/model/Component.js

13
src/dom_components/model/Component.js

@ -1402,16 +1402,21 @@ export default class Component extends Model.extend(Styleable) {
} }
} }
const comps = model.get('components');
const content = !comps.length ? model.get('content') : '';
const attrString = attrs.length ? ` ${attrs.join(' ')}` : ''; const attrString = attrs.length ? ` ${attrs.join(' ')}` : '';
let code = `<${tag}${attrString}${sTag ? '/' : ''}>${content}`; const inner = model.__innerHTML(opts);
comps.forEach(comp => (code += comp.toHTML(opts))); let code = `<${tag}${attrString}${sTag ? '/' : ''}>${inner}`;
!sTag && (code += `</${tag}>`); !sTag && (code += `</${tag}>`);
return code; return code;
} }
__innerHTML(opts = {}) {
const cmps = this.components();
return !cmps.length
? this.get('content')
: cmps.map(c => c.toHTML(opts)).join('');
}
/** /**
* Returns object of attributes for HTML * Returns object of attributes for HTML
* @return {Object} * @return {Object}

Loading…
Cancel
Save