-
Notifications
You must be signed in to change notification settings - Fork 2k
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
KnockoutJS data binding support #17
Conversation
Added KnockoutJS support by using a custom 'multiselect' binding handler. Example: 1. Define select input ------------------------- <select class="multiSelect" data-bind="multiselect: true,options: Options, selectedOptions: SelectedOptions, optionsValue: $data" multiple="multiple"></select> 1. Initialize Bootstrap-multiselect ------------------------------------- $(".multiSelect").multiselect(); 3 .Apply view model
Ok, cause I do not know anything about Knockout JS I can not help you with your problem, lucastschmidt. I am just reviewing the pull request. One question: Why rebuilding the whole option list on the refresh method? Is this important for working with Knockout JS? Because I just started implementing a real rebuild functionality. I will merge your pull request, but will not test the plugin with Knockout JS! It would be nice if you could test it with Knockout JS after the next commit. Thanks for your contribution! |
KnockoutJS data binding support.
Complete rebuilding is important when using KnockoutJS since KnockoutJS is often used to bind an array to a as options. Currently your edit is not working, but the fix is easy. I have placed a comment on the specific line in your commit. Thanks for the awesome plugin! |
Here is the change commit on my fork Devristo/bootstrap-multiselect@b8adf3cb38912d623f6972d408e96fde867e2343 |
Sorry... once I realized what was going on, I realized that because I was binding to a list of viewmodel I needed to ensure the optionsValue was being set. Little did I understand ahead of time, this option expect something like "id" a string representation of the value property. |
Yeah, optionValue is required when data binding :) |
Added KnockoutJS support by using a custom 'multiselect' binding handler.
The github diff is wrong. I only added the 'ko' related code at the top and changed the 'refresh' method and moved the creation of options into a function addOptions.
Example:
1. Define select input
Note the multiselect: true binding!
2. Initialize Bootstrap-multiselect
3 .Apply Knockout view model
As usual
Notes
It is important to do initialize multiselect before applying the view model, since the custom binding code will hook into the onChange method to update the binding.