concatenate valueConverters in a single statement
avizcaino opened this issue · 2 comments
Hi! I would like to know if there is a way to concatenate multiple value converters as follows:
<compose
if.bind="record | toBoolean && header | toBoolean"
model.bind="header"
view-model="./details/detail-header">
</compose>
The framework gives an error due to the &&
operator... I've found a workaround creating a multiple-parameter converter, but it would be great to know if it is possible to concatenate multiple valueconverters together in a single statement... This way I won't need to create a specific converter for cases like this one.
Thanks!
you can use multiple value converters- the syntax won't allow you to do what you're attempting above ^^^ though. It looks more like this:
[javascript expression][value converter expessions]
A concrete example (using "substring" and "upper case" converters):
<div textcontent.bind="foo.bar.baz | substring:3:12 | upper"
</div>
You could refactor your binding expression to something like this:
<compose
if.bind="record && header"
model.bind="header"
view-model="./details/detail-header">
</compose>
But I'm guessing this isn't working for you which is why you need the toBoolean
. You could add a toBoolean
function to your viewmodel and then do something like this:
<compose
if.bind="toBoolean(record) && toBoolean(header)"
model.bind="header"
view-model="./details/detail-header">
</compose>
Or maybe an "and" value converter like this:
export class AndValueConverter {
toView(...values) {
return values.reduce((a,b) => toBoolean(a) && toBoolean(b), true);
}
}
if.bind="record | and:header"
what do you think?
yeah... the last option is the one I finally applied...
Refactoring the binding expression didn't work at all (aurelia gives an error due to the &&
expression) whether it is a couple of booleans or a call to some function in my view-model.
It would be great in the future to have something to be able to concatenate different value converters results without the need to implement a custom-one.
Thanks anyway!!