Убрать тег родительского компонента - PullRequest
0 голосов
/ 02 июля 2018

Я объявил элемент <table> в HTML-шаблоне и поместил custom-component в его строку, например:

<table>
  <thead>
    ....
  </thead>
  <tbody>
    <tr>
      <CustomComponent></CustomComponent>
    </tr>
  </tbody>
</table>

CustomComponent содержит некоторые <td> с.
я хочу снять <CustomComponent></CustomComponent>, чтобы внутренние <td> s были первыми детьми <tr>.

1 Ответ

0 голосов
/ 02 июля 2018

Я попробовал и протестировал нижеприведенное, надеюсь, это должно работать.

   // select element to unwrap
    var el = document.getElementsByTagName("CustomComponent");

    // get the element's parent node, if it returns array then take the first index
    var parent = el[0].parentNode;

    // move all children out of the element
    while (el[0].firstChild) {
        parent.insertBefore(el[0].firstChild, el[0]);
    }

    // remove the empty element
    parent.removeChild(el[0]);

Счастливого кодирования!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...