我花了很多時間將其他參數添加到Jquery-Autocomplete-Source。但我無法完成。無法將表單值附加到Jquery自動完成源
我在做什麼:我有一個jQuery數據源的自動完成表單。如果您從自動填充中選擇了一些內容,它將被插入到一個表格中(文本和一個帶有ID的隱藏字段),並啓動功能lesen
(正常工作)。函數lesen
將具有「類」nutzerid
(隱藏字段)的每個元素的值讀取到數組並將其放入輸入字段 - 輸入字段是所有id(works!)的收集器。但!自動完成應該讀取該字段的值,並將其作爲參數發送給我的JSON源。但事實並非如此。 Firebug控制檯顯示一個空的參數。即使警報能夠顯示值。我真的不知道,我做錯了什麼。
我也嘗試用一個變量替換輸入字段(所有ID的收集器)。但是同樣的問題發生在這裏。我可以提醒var的值。但試圖將其附加到源代碼會產生一個空的參數。我也嘗試通過param,extraparams選項給自動完成的值。沒有成功。我認爲加入陣列存在問題。可能是lesen
中的步驟,其中所有id都被推送到一個數組,並且該數組被填充到表單中。但我不知道如何解決這個問題。
爲什麼我這麼做?我希望JSON源PHP能夠排除其MySQL查詢中已經選擇的ID。以前的請求中選擇的內容不應與自動填充一起顯示。所以我必須發佈,之前添加到請求頁面的內容。這就是我選擇的方式(可能不是最乾淨的)。想象一下購物車。如果產品附加到購物車,則不應在將來的請求中顯示。當然,我接受新的方法。
<input type="text" id="ausschluss" />
$(document).ready(
function() {
//this functions reads every hidden field (form the added items) an puts the array as string to a hidden field
function lesen(){
var itemsarray = [];
$(".nutzerid").each(function() {
var items = $(this).attr('value');
itemsarray.push(items);
});
$("#ausschluss").val(itemsarray);
};
//this function attaches the selection (from the autocomplete) to a table it creates text, a hidden field with the user id and a button
function log(name, id) {
$("<tr> <td>" + name + "<input class='Entf' type='button' value ='Entfernen' />" + "<input type='hidden' class='nutzerid' name='hiddenField' value='" + id + "' /></td></tr>").appendTo("#log");
$("#log").attr("scrollTop", 0);
lesen();
}
//this is the autocompletepart
$("#REMOTE").autocomplete({
source: "json.php?aus=" + $("#ausschluss").val(), //this is not working. the firebug console shows an empty param (.php?aus=&term=blabla
minLength: 2,
select: function(event, ui) {
log(ui.item.value,ui.item.id);
alert($("#ausschluss").val()); //this works! after selecting an item from the autocomplete it shows me the value of the field "ausschluss", like it should be appended to the source
}
});
//this one captures the click of a button. identified by the class and kills the <tr> <td> and all elemtns in it
$('.Entf').live('click',function(event){
$(this).parent().parent().remove();
lesen();
});
});
就是這樣!大!非常感謝!!! – brill 2011-04-06 06:57:56
Keine Ursache .. – 2011-04-06 09:11:11