簡體   English   中英

功能為源的JQuery UI自動完成代碼問題

[英]JQuery UI AutoComplete Code Issue with Function as Source

因此,從本質上講,我嘗試移至一個為autocomplete方法中的source參數完成工作的函數,現在腳本已損壞。 即使$.get(...)請求返回值,鍵入時也不會顯示任何選項。

HTML:

           <tr class="itemTableRow">
                <td>
                    <input type="text" class="item" name="items[]" />
                </td>
                <td>
                    <input type="range" class="quantity" min="1" max="10000" name="quantity[]" />
                </td>
                <td>
                    <select class="versionSelect"><option value="5">5</option><option value="6">6</option><option value="7">7</option></select>
                </td>
            </tr>

Javascript:

 $(function() {

            $( ".item" ).autocomplete({
                            source: function(request, response){var data = $.get("http://mydomain.com/dev/kohana/utils/items/search?searchType=maxList&amp;term=" + request.term + "&amp;version=" + $(".item").parent().parent().children(":nth-child(3)").children("select").val()); console.log("" + data); response(data);},
                            minLength: 2
                        });
});

結果HTTP GET請求URL(在輸入字段中輸入CP時):

http://mydomain.com/dev/kohana/utils/items/search?searchType=maxList&term=CP&version=5

結果HTTP響應正文:

[{"label":"CP1031L","value":"CP1031L"},{"label":"CP1031M", "value":"CP1031M"]

我在頁面上還包含了Jquery UI默認樣式表,盡管在此之前它是可行的。 我覺得我在功能回調應該如何工作方面缺少了一些非常基本的知識。 有人可以發現問題嗎? 謝謝您的幫助。

您應該在.get()調用的成功處理程序上調用response(data) ,如下所示:

$( ".item" ).autocomplete({
                            source: function(request, response){var data = $.get("http://mydomain.com/dev/kohana/utils/items/search?searchType=maxList&amp;term=" + request.term + "&amp;version=" + $(".item").parent().parent().children(":nth-child(3)").children("select").val(), function(data) {response(data);});},
                            minLength: 2
                        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM