The Vaadin Elements team has just released a new update for <vaadin-combo-box> that enables custom item templates for combo box items. With custom templates, your combo box can consume the items array to display more complex HTML, such as including an index, adding an image, displaying multiple fields from the item data, or simply making the item bold or italic. Custom templates also allow you to display multiple fields from the data items, if you set the combo box’s items property to an array of objects.

For example:

<vaadin-combo-box items='[{"label": "Hydrogen", "value": "H"}]'> <template> [[index]]: [[item.label]] <b>[[item.value]</b> </template> </vaadin-combo-box>

This will create a combo box where the items will be listed as:

1: Hydrogen **H** Custom styles for item templates

With item templates, you can also style the displayed item. To do this, you need to create a new custom element with its own styles and template. You can also use any existing elements, such as <paper-item>, which is a natural fit for combo box items. The <paper-item> element can be easily used for this purpose.

For more information, see our docs page for Styling Combo Box Items with Custom Item Element.

Use Item Templates with &lt;vaadin-combo-box&gt; to Customize the Item List ...
Focused and Selected

There are several new variables you can bind from within the item template to further customize the displayed item. These variables are index , focused , and selected .

index displays the number index of that item, as shown in the first example above. focused is true when the user is focused on that item, such as with keyboard navigation. selected is true when the item is the selected item for the combo box.

Learn more about <vaadin-combo-box> at the Vaadin Elements page.

Use Item Templates with &lt;vaadin-combo-box&gt; to Customize the Item List ...

Juniper Belmont is a genderqueer developer advocate passionate about the open web platform. They love meeting people, talking about their passions, and giving presentations interspersed with bawdy jokes and lavish, mostly true stories. They use they/them pronouns and they can be found @juniperbelmont

41 Views, 0 Comments

Average (0 Votes)

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: HTML
tags: lt,combo,gt,box,items,index
本文标题:Use Item Templates with &lt;vaadin-combo-box&gt; to Customize the Item List ...

技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(112)