Ahr*_*Jon 3 data-binding html-table filter polymer
Polymer中有什么东西或多或少等同于AngularJS'过滤器'功能吗?我查看了模板绑定,但无法根据输入字段的值找到过滤表格的方法...
<input value="{{ID}}">
<table [==> some Polymer magic here involving {{ID}}]>
<tr>
<th>ID</th>
<th>VALUE</th>
</tr>
<tr>
<td>FOO</td>
<td>1</td>
</tr>
<tr>
<td>BOO</td>
<td>2</td>
</tr>
<tr>
<td>FAA</td>
<td>3</td>
</tr>
<tr>
<td>BAA</td>
<td>4</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
然后在输入字段中键入"F"将使表格仅显示值等于1和3的行,并且继续显示"O"将仅显示"1"...
执行此操作(今天)的最佳方法是从过滤后的数据模型生成表,并使用Polymer on-*处理程序对输入进行反应
<polymer-element name="my-element">
<template>
<input type="text" on-keyup="{{filter}}">
<table>
<tr><th>ID</th><th>VALUE</th></tr>
<template repeat="{{d in filteredData}}">
<tr><td>{{d[0]}}</td><td>{{d[1]}}</td></tr>
</template>
</table>
</template>
<script>
Polymer('my-element', {
created: function() {
this.data = [
['FOO', 1], ['BOO', 2], ['FAA', 3], ['BAA', 4]
]
this.filteredData = this.data;
},
filter: function(e, detail, sender) {
// Tests for anywhere in the string. Modify to match just the beginning.
var regex = new RegExp(sender.value, 'i');
this.filteredData = this.data.filter(function(d, idx, array) {
return regex.test(d[0]);
});
}
});
</script>
</polymer-element>
<my-element></my-element>
Run Code Online (Sandbox Code Playgroud)
演示:http://jsbin.com/parive/2/edit?html,output
将来,我们将在表达式中添加对过滤器函数的一流支持.见1和2.
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |