好了Twitter的引导预输入选择,我这个问题,现在争取小时,缩小了问题很简单Fiddle不受KnockoutJS约束
问题是,当我使用Twitter的引导的预输入插件上一个文本输入并进行选择,该值不会在KnockoutJS ViewModel中更新。我知道我可以破解它的工作,但必须有一些我在这里失踪的东西。
基本上我有是:
淘汰赛绑定
// Bind twitter typeahead
ko.bindingHandlers.typeahead = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var $element = $(element);
var allBindings = allBindingsAccessor();
var typeaheadArr = ko.utils.unwrapObservable(valueAccessor());
$element.attr("autocomplete", "off")
.typeahead({
'source': typeaheadArr,
'minLength': allBindings.minLength,
'items': allBindings.items,
'updater': allBindings.updater
});
}
};
淘汰赛视图模型
function MyModel(){
var self = this;
self.productName = ko.observable();
self.availableProducts = ['One', 'Two', 'Three'];
}
ko.applyBindings(new MyModel());
HTML
<input type="text" data-bind="typeahead:availableProducts, value:productName"/>
其余的东西只是来自Twitter Bootstrap。
我不是绑定的作者。原始绑定在这里:https://github.com/billpull/knockout-bootstrap我不知道我是否错过了用法中的某些东西? –