就我個人而言,我有一個模擬「地圖」的功能,我在哪裏添加「Key」菜單項和「Values」菜單子項。
此功能可以在下面
var key;
var value;
var mapaDeListas = new Array();
$(".conteudoMenu a").click(function(){
key = $(this).parent(".conteudoMenu").parent("li").find(".itemMenu").attr("id");
value = $(this).attr("id");
Processar();
console.log(mapaDeListas);
});
var Processar = function() {
if (mapaDeListas[key] && $.inArray(value, mapaDeListas[key]) == -1 || mapaDeListas[key] && $.inArray(value, mapaDeListas[key]) != -1) {
// Checks if the key already exists from the "key" and if the value of "value" is present in the array
if (mapaDeListas[key].indexOf(value) == -1){
mapaDeListas[key].push(value);
}
}
else {
// Creates the array according to the value of the "key" and adds the value of "value"
mapaDeListas[key] = new Array();
mapaDeListas[key].push(value);
}
}
觀看,我想知道的是我如何通過在阿賈克斯這個函數的值到Servlet並通過他們向裝配Java中的地圖是什麼。
我試圖通過Ajax如下如下發送此函數的值,但沒有效果
function loadQuery(){
if(inputMenu.length > 0){
$.ajax({
url: "assembles-query",
type: "POST",
data: {
"mapaDeListas[]" : mapaDeListas
},
//dataType: "json",
error:function(){
alert("ERRO MENU")
},
success:function(responseText){
$("textarea[id=assembleQuery]").text(responseText);
}
});
}
}
在Servlet,試圖得到的結果如下字符串[] mapaDeListas = request.getParameterValues ( 「mapaDeListas []」);
但是,當我發送打印結果總是返回null。
有人會告訴我我錯了什麼,我該怎麼做才能正確傳遞這些值? 既然已經感謝大家的幫助。
下面打印瞭如何存儲結果。 http://bit.ly/V9oHsg
我不確定這個''mapaDeListas []「:mapaDeListas'會啓動。可能是你應該嘗試建立你自己的GET URL('url:「彙編 - 查詢,'')並追加數組的每個元素 – MatRt 2013-02-11 00:20:57
當我嘗試打印我的loadQuery函數中的mapaDeListas(){} 。就好像這些值沒有存儲在mapaDeListas中。那你會說這個建議嗎? – 2013-02-11 00:30:01