我过去曾使用过一种方法将paper-input
设为空白,但是当与Vaadin-grid
结合使用时,我常用的方法不起作用。
我在这里遗漏了什么吗?
Vaadin 网格 HTML
<vaadin-grid-column>
<template class="header">
<div class="horizontal layout cell">
<label for="keyFilter" class="keyText cell flex">Key</label>
<vaadin-grid-filter class="cell" id="keyFilter" path="key" value="[[_filterKey]]">
<paper-input no-float-label class="keyFilter" id="keyFilter" slot="filter" placeholder="Filter search" value="{{_filterKey::input}}" focus-target on-input="clearAppear" >
<iron-icon suffix icon="clear" class="clearIcon" on-click="clearField" clear-item-id="keyFilter"></iron-icon>
</paper-input>
</vaadin-grid-filter>
</div>
</template>
<template class="cell">[[item.key]]</template>
</vaadin-grid-column>
我尝试了以下 JS:
// Attempt 1 - gives "undefined" within the dev tools
this.$.keyFilter.value = '';
// Attempt 2 - finds the correct element, but does not set the value to blank
document.getElementById('keyFilter').value = ''
最佳答案
要在元素的影子 DOM 中定位动态创建的节点,请使用标准 DOM querySelector
方法:
this.shadowRoot.querySelector(选择器)
因此,对于您的问题,请使用 this.shadowRoot.querySelector("#keyFilter").value='';
您在上面的代码中犯了一个简单的错误,即为 vaadin-grid-filter
和 paper-input
提供相同的 id
名称元素。请确保在尝试上述代码之前更改此设置。
关于javascript - 无法清除 Vaadin-grid 中的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45816468/