Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optionsValue to accept an array map #727

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Allow optionsValue to accept an array map #727

wants to merge 2 commits into from

Conversation

nathanboktae
Copy link

My initial instinct on using optionsValue was to pass it an array that was a map of the values in the options box, but I was surprised that it wasn't supported. This is very common for things that need to be localized.

@mbest
Copy link
Member

mbest commented Nov 22, 2012

Since optionsValue can be a function, it's easy enough to make it do what you want. Maybe we could add the index as a second parameter to the function since it looks like you want to use the index as input.

@nathanboktae
Copy link
Author

It is easy enough to use a function, but to keep views logicless as possible and view models as simple as possible, it's nice to have. I bring up localization as it can be such a cross cutting concern and not something you would want to put on every view model.

var l10n = {
  'ko-KR': {
    cat: '고양이',
    dog: '개',
    bird: '새'
  }
};
var model = {
  pets: ['cat', 'dog', 'bird'];
};
<select data-bind="options: pets, optionsText: l10n['ko-KR']"></select>

Though with the first commit, I didn't have that situation flushed out :) For such a low-impact, trivial work it seems nice to flush out the usage of this binding a bit more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants