简体   繁体   English

如何从文本节点中删除所有节点?

[英]How to remove all nodes from text node?

I'm trying to clear the nodes from the text node,我正在尝试从文本节点中清除节点,

The node i get in which it has _nodes which i want clear/remove我得到的节点有_nodes ,我想清除/删除

Element {parent: Element, _attrs: Map(8), name: 'tableCell', _children: NodeList}
name: "tableCell"
parent: Element {parent: Element, _attrs: Map(2), name: 'tableRow', _children: NodeList}
 _children: NodeList
   _nodes: Array(2)
     0: Text {parent: Element, _attrs: Map(3), _data: '0.75'}
     1: Text {parent: Element, _attrs: Map(0), _data: '%'}
      length: 2
      [[Prototype]]: Array(0)

Here i'm trying to remove it but the node.getChildren() only get the _nodes[0] element/string from the node and removes it.在这里,我试图将其删除,但node.getChildren()仅从节点获取_nodes[0]元素/字符串并将其删除。

    _removeAllTextNodes (node,writer) {
        if (node != null) {
            if (node.is('$text')) {
                // writer.remove(node);
                console.log('node :>> ', node);
            }

            for (const childNode of node.getChildren()) {
                console.log(childNode);
                 writer.remove(childNode);
           }
        }
    }

This is what it shows after the _nodes[0] is removed how do i remove this node too?这是删除_nodes[0]后显示的_nodes[0] ,我该如何删除此节点?

Element {parent: Element, _attrs: Map(8), name: 'tableCell', _children: NodeList}
name: "tableCell"
parent: Element {parent: Element, _attrs: Map(2), name: 'tableRow', _children: NodeList}
 _children: NodeList
   _nodes: Array(1)
        0: Text {parent: Element, _attrs: Map(0), _data: '%'}
         length: 1
         [[Prototype]]: Array(0)

It's impossible for child nodes to have children of any kind, so the the premise of your question "I'm trying to clear the nodes from the text node" is impossible.子节点不可能有任何类型的子节点,因此您的问题“我正在尝试从文本节点中清除节点”的前提是不可能的。

https://stackoverflow.com/a/1111282/694325 https://stackoverflow.com/a/1111282/694325

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM