mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Late-bind filter and sort functions.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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'},
|
||||
|
||||
Reference in New Issue
Block a user