【发布时间】:2015-06-21 10:48:56
【问题描述】:
我的聚合物元素中有一个表格,我希望它根据输入字段中提供的关键字过滤行
<polymer-element name="my-element">
<template>
<paper-input label="Search" floatingLabel="false" class="search-main" on-keyup="{{search}}"></paper-input>
<table id="table">
<thead>
<tr>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Cr</td>
<td>Smith</td>
</tr>
<tr>
<td>keety</td>
<td>cros</td>
<td>bran</td>
</tr>
</tbody>
</table>
</template>
<script>
Polymer('my-element', {
search: function() {
var rows = this.$.table.querySelector('tr');
var val = '^(?=.*\\b' + $.trim($(this).val()).split(/\s+/).join('\\b)(?=.*\\b') + ')',
reg = RegExp(val, 'i'),
text;
$(rows).show().filter(function() {
text = $(this).text().replace(/\s+/g, ' ');
return !reg.test(text);
}).hide();
}
})
;
</script>
</polymer-element>
没有收到任何控制台错误但过滤器不起作用
我是聚合物新手,所以请告诉我我做错了什么?
【问题讨论】:
-
根据 Polymer 文档,
this.$.table引用应引用 id 为table的元素,但是您的表没有 id 属性。尝试将<table>更改为<table id="table">。 -
哦,这是在我的代码中,不小心被我删除了……我已经编辑了我的帖子
标签: jquery polymer tablefilter