2017-05-09 56 views
0

我想实现自动完成使用jQuery UI但自动完成文本框是在“与”敲除绑定,所以MVC行动永远不会被解雇。jQuery自动完成不射击行动当元素是内敲除“与”绑定

<div data-bind="with: activeButton"> 
//Some other div's... 
    <div> 
    <input type="text" id="autoCompleteText" data-autocomplete-url="@Url.Action("Autocomplete")"/> 
    </div> 
</div> 

//On DOM ready 
$('*[data-autocomplete-url]').each(function() { 
     $(this).autocomplete({ 
      source: $(this).data("autocomplete-url") 
     }); 
    }); 

当自动完成元素在“with”敲除绑定中时,我是否必须做出与MVC动作不同的动作?

+0

你有没有意识到存在 “数据autocomplete- URL” 的空间?如果这是你的代码,那么它可能会打破它。 – Drummad

+0

修正了它。谢谢! – Amit

+0

这不是我的代码。 – Amit

回答

1

您将需要jquery ui autocomplete的knockout绑定处理程序。喜欢的东西

<div data-bind="with: activeButton"> 
//Some other div's... 
     <input type="text" id="autoCompleteText" data-bind='textInput: someSelectedValue, autoComplete:{source: "@Url.Action("Autocomplete")" }' /> 
</div> 

淘汰赛结合

ko.bindingHandlers.autoComplete = { 
    init: function(element, valueAccessor) { 
     var autoCompleteOptions = ko.unwrap(valueAccessor()); // Get the current value of the current property we're bound to 
     $(element).autocomplete(autoCompleteOptions); 
    } 
};