com.vaadin.flow.dom.Element.getChildCount()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中com.vaadin.flow.dom.Element.getChildCount()方法的一些代码示例,展示了Element.getChildCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getChildCount()方法的具体详情如下:
包路径:com.vaadin.flow.dom.Element
类名称:Element
方法名:getChildCount

Element.getChildCount介绍

[英]Gets the number of child elements.

If the property "innerHTML" has been set explicitly then its value (the new element structure) won't be populated on the server side and this method will return 0.
[中]获取子元素的数目。
如果已显式设置属性“innerHTML”,则不会在服务器端填充其值(新元素结构),此方法将返回0

代码示例

代码示例来源:origin: com.vaadin/flow-server

private Stream<Element> flattenChildren(Element node) {
  if (node.getChildCount() > 0) {
    return node.getChildren().flatMap(this::flattenChildren);
  }
  return Stream.of(node);
}

代码示例来源:origin: com.vaadin/flow-data

/**
   * Gets the index of the child element that represents the given item.
   * 
   * @param item
   *            the item to look for
   * @return the index of the child element that represents the item, or -1 if
   *         the item is not found
   */
  default int getItemPosition(T item) {
    if (item == null) {
      return -1;
    }
    return IntStream.range(0, getElement().getChildCount()).filter(i -> {
      Optional<Component> c = getElement().getChild(i).getComponent();
      return c.isPresent() && c.get() instanceof ItemComponent
          && item.equals(((ItemComponent<?>) c.get()).getItem());
    }).findFirst().orElse(-1);
  }
}

代码示例来源:origin: com.vaadin/vaadin-button-flow

private void updateThemeAttribute() {
    // Add theme attribute "icon" when the button contains only an icon to
    // fully support themes like Valo. This doesn't override explicitly set
    // theme attribute.

    if (getElement().getChildCount() == 1 && iconComponent != null) {
      getThemeNames().add("icon");
    } else {
      getThemeNames().remove("icon");
    }
  }
}

代码示例来源:origin: com.vaadin/flow-server

private void setTextContent(String textContent) {
  Element child;
  if (getChildCount() == 1 && getChild(0).isTextNode()) {
    child = getChild(0).setText(textContent);
  } else {
    child = createText(textContent);
  }
  removeAllChildren();
  appendChild(child);
}

相关文章

微信公众号

最新文章

更多