KnockoutJS jQuery组合框绑定 [英] KnockoutJS JQuery Combobox Binding
问题描述
我想对使用 JQuery自动完成组合框的剔除进行绑定并允许双向绑定.
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/ https://stackoverflow.com/questions/7537002/autocomplete-combobox-with-knockout-js-template-jquery>这个问题已经开始,但并未像jQuery演示站点. (例如,选择突出显示,按钮样式,按钮未提交表单等).
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.).
推荐答案
我使用了 http://harvesthq. github.com/chosen/在我的项目中.它可以完美地在标准HTML控件SELECT上运行.因此,我使用标准绑定来管理SELECT(选项,值,selectionOptions)和其他自定义绑定chosen
,以将标准控件转换为精美的控件.
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.
您可以查看用法示例: http://jsfiddle.net/romanych/PcXrP/6/
You could checkout usage example: http://jsfiddle.net/romanych/PcXrP/6/
有绑定代码.很简单
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");
}
};
这篇关于KnockoutJS jQuery组合框绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!