Late-bind filter and sort functions.

This commit is contained in:
Kevin Schaaf
2015-05-08 18:22:07 -07:00
parent 271a9e3b07
commit 38eab2cb50
2 changed files with 21 additions and 4 deletions

View File

@@ -222,8 +222,9 @@ Then the `observe` property should be configured as follows:
_sortChanged: function() {
var dataHost = this._getRootDataHost();
this._sortFn = this.sort && (typeof this.sort == 'function' ?
this.sort : dataHost[this.sort].bind(dataHost));
var sort = this.sort;
this._sortFn = sort && (typeof sort == 'function' ? sort :
function() { return dataHost[sort].apply(dataHost, arguments); });
this._fullRefresh = true;
if (this.items) {
this._debounceTemplate(this._render);
@@ -232,8 +233,9 @@ Then the `observe` property should be configured as follows:
_filterChanged: function() {
var dataHost = this._getRootDataHost();
this._filterFn = this.filter && (typeof this.filter == 'function' ?
this.filter : dataHost[this.filter].bind(dataHost));
var filter = this.filter;
this._filterFn = filter && (typeof filter == 'function' ? filter :
function() { return dataHost[filter].apply(dataHost, arguments); });
this._fullRefresh = true;
if (this.items) {
this._debounceTemplate(this._render);

View File

@@ -39,6 +39,18 @@
</div>
</template>
<h3>Show person by index, demonstrate filter</h3>
<template is="dom-repeat" items="{{employees}}" filter="onlyRob">
<div>
<div style="padding: 3px 0px;">
<button on-tap="modify">Modify</button>
<span>{{index}}</span>
<span>{{item.first}}</span>
<span>{{item.last}}</span>
</div>
</div>
</template>
</template>
<script>
@@ -50,6 +62,9 @@
app.modify = function(e) {
e.model.set('item.last', e.model.item.last + '*');
};
app.onlyRob = function(item) {
return item.first == 'Rob';
};
app.bar = true;
app.employees = [
{first: 'Bob', last: 'Smith'},