Это настраиваемая привязка для нокаута, которую я написал с помощью поля типа BootStrap. Все работает, как ожидалось, но единственный вопрос, который я имею, что всякий раз, когда я очищаю мое поле нокаут наблюдаемого еще содержит последнее действительное selection.Not уверено, что я делаю неправильно ..Пользовательский привязку нокаута с бутстрапом Проблема с типом с пустыми значениями
ko.bindingHandlers.productTypeahead = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
{
var root = bindingContext.$root;
var options = ko.unwrap(valueAccessor()) || {},
$el = $(element);
options.source = _.debounce(function (query, process) {
root.api.SearchProducts(query)
.done(function (data) {
process(data);
}).fail(function (xhr) {
root._alert.error("Could not search products - " + JSON.parse(xhr.responseText).ExceptionMessage);
});
} , 300);
$el.attr("autocomplete", "off")
.typeahead({
source: options.source,
autoSelect: true,
displayText: function (item) { return item != null ? item.id : ""; },
matcher: function() { return true; },// api does this already
items: 15,
minLength: 3,
updater: function (item) {
options.value(item);
},
highlighter: function (item) {
var query = this.query;
query = query.replace(/[^\w\']+/g, "|");
var queryRegex = new RegExp("\\b(" + query + ")", "gi");
return item.replace(queryRegex, "<strong>$1</strong>");
}
});
// if KO removes the element via templating, then destroy the typeahead
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$el.typeahead("destroy");
$el = null;
});
}
};