Skip to content

Instantly share code, notes, and snippets.

@charlespockert
Created September 7, 2015 07:46
Show Gist options
  • Save charlespockert/ae1eb4a8196b129e2a9a to your computer and use it in GitHub Desktop.
Save charlespockert/ae1eb4a8196b129e2a9a to your computer and use it in GitHub Desktop.
Bumping an array filtering value converter in Aurelia
export class TestValueConverter {
toView(value, selected, rebind) {
console.log("Running value converter");
return value.filter(val => {
var found = false;
selected.forEach(sel => {
if (val.toLowerCase().indexOf(sel) > -1)
found = true;
});
return found;
});
}
}
export class ViewModel {
testPeople = ["Charles", "Fred", "John", "James", "Steve", "Andy", "Martin", "Dan", "Paul", "Anne", "Joseph", "Chris", "Jams", "Francis"];
testFinders = ["ch", "fr", "jo", "ja", "st", "an"];
selectedFinders = [];
testFlag = false;
constructor(observerLocator:ObserverLocator)
{
observerLocator.getArrayObserver(this.selectedFinders).subscribe(() => {
this.testFlag = !this.testFlag;
});
}
}
<template>
<require from=".test-value-converter"></require>
<label repeat.for="item of testFinders">
<input type="checkbox" checked.bind="$parent.selectedFinders" value.bind="item" />${item}
</label>
${selectedFinders}
<div repeat.for="person of testPeople | test:selectedFinders:testFlag">
<p>${person}</p>
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment