2017-05-09 60 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); 
    } 
};