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

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

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

Element.getChild介绍

[英]Returns the child element at the given position.

If 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 not work.
[中]返回给定位置的子元素。
如果已显式设置属性“innerHTML”,则其值(新元素结构)将不会在服务器端填充,并且此方法将不起作用。

代码示例

代码示例来源: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);
}

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

private static Optional<AccordionPanel> getOpenedPanel(Accordion accordion, Integer index) {
  return index == null || index >= accordion.getChildren().count() ? Optional.empty() :
      accordion.getElement().getChild(index).getComponent().map(AccordionPanel.class::cast);
}

代码示例来源: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);
  }
}

相关文章

微信公众号

最新文章

更多