I'm trying to create a generic filter Value Converter to use in a few cases. I would like to be able filter the items in the array by properties on sub objects like this:
<li repeat.for="row of router.navigation | filter:'settings.where':'top'" >
I know I'm going to have to parse the settings.where
expression to get to the value. So far I have cobbled together the following:
import {inject, Parser} from 'aurelia-framework'
@inject(Parser)
export class FilterValueConverter {
constructor(parser) {
this.parser = parser;
}
toView(array, property, exp) {
let expression = this.parser.parse(property);
return array.filter((item) => expression.evaluate(...?) === exp);
}
}
The parse
appears to give me an expression but was the Parser designed to be used outside the core framework? evaluate
requires a scope and I don't have one of those... I could walk the expression tree and get the result myself but does something like this already exist?