knockout / tko

🥊 Technical Knockout – The Monorepo for Knockout.js (4.0+)
http://www.tko.io
Other
273 stars 34 forks source link

optionsText with a lambda value fails to resolve the function argument #146

Closed danieldickison closed 2 years ago

danieldickison commented 2 years ago

I tried a lambda (arrow-function) value for optionsText, following the knockout docs’ example, which uses a function value:

<select data-bind="
    options: possibleUsers,
    optionsText: (user) => formatUser(user),
    value: selectedUser
"></select>

This fails with:

Message: The variable \"user\" was not found on $data, $context, or globals.

Specifying the optionsText as a function reference does work: optionsText: formatUser

Demo: https://jsfiddle.net/danieldickison/az2on6h0/4/

brianmhunt commented 2 years ago

Good find, thanks. This would seem to be a problem with the bindingContext lookup function.

A PR with a failing test would be a good starting point.

Glad you've a workaround with the formatUser, in the interim.

danieldickison commented 2 years ago

Tests in #151 and it looks like lambda parameter lists aren't being evaluated at all at the moment, and multiple parameters fail to parse. I've been looking at parser.ts but haven't quite wrapped my head around how all the parts fit together.

@brianmhunt do you think you would be able to look into this soon? If not, I'll continue developing a fix in the parser over the next couple of days.

edit: the pull request now has a fix for this in it.