KnockoutJS JQuery Combobox Binding

大城市里の小女人 提交于 2020-01-01 06:19:14

问题


I'd like to make a binding for knockout which uses the JQuery Autocomplete Combobox and allows for 2 way binding.

http://jsfiddle.net/rniemeyer/PPsRC/ from this question has gotten a start, but doesn't fully implement the combobox functionality as on the jQuery demo site. (ie. selection highlighting, button styling, button not submitting the form, etc.).


回答1:


This is a bit late, but I have a two way autocomplete combo box binding in my Knockout UI library (see Dropdown). Take a look and see if it helps.

Thanks




回答2:


I have used http://harvesthq.github.com/chosen/ in my projects. It works perfectly over standard HTML control SELECT. So I have used standard bindings for managing SELECT (options, value, selectionOptions) and additional custom binding chosen to convert standard control to fancy one.

You could checkout usage example: http://jsfiddle.net/romanych/PcXrP/6/

There is code of binding. It is pretty simple

ko.bindingHandlers.chosen = {
    init: function(elemenet, valueAccessor) {
        var chosenOptions = ko.utils.unwrapObservable(valueAccessor());
        $(elemenet).chosen(chosenOptions);
    },
    update: function(elemenet, valueAccessor, allValuesAccessor) {
        // Subscribe to any change of underlying SELECT-element
        ko.utils.unwrapObservable(allValuesAccessor().value);
        ko.utils.unwrapObservable(allValuesAccessor().options);
        ko.utils.unwrapObservable(allValuesAccessor().selectedOptions);
        $(elemenet).trigger("liszt:updated");
    }
};


来源:https://stackoverflow.com/questions/7905975/knockoutjs-jquery-combobox-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!