就我个人而言,我有一个模拟“地图”的功能,我在哪里添加“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