Created
September 7, 2015 07:46
-
-
Save charlespockert/ae1eb4a8196b129e2a9a to your computer and use it in GitHub Desktop.
Bumping an array filtering value converter in Aurelia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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