0
我试图将2d数组传递给函数。但是当我循环访问setParams
中的数组时,数组中有一些额外的值(发生在switch
中的每case
),我不知道它们来自哪里。如何通过值函数传递二维数组
function setParams(button, params) {
$mydialog = $("#dialog").dialog({
autoOpen: true,
buttons: {
"ok": function() {
$(this).dialog("close");
for(var key in params) {
var value = params[key].toString();
var arr = value.split(',');
alert(arr[0] + " " + arr[1]);
var control = $("#dialog").find('input[name='+arr[1]+']');
if (control.is(':checkbox'))
{
button.data('id')[arr[0]] = control.is(":checked");
}
else
{
button.data('id')[arr[0]] = control.val();
}
}
sendRequest(button);
},
"cancel": function() {
$(this).dialog("close");
}
}
});
}
菜单功能
$(function() {
$('#navigationMenu a').click(function(e) {
e.preventDefault();
e.stopPropagation();
var button = $(this);
var cl = button.attr("class");
console.log(button.attr('href'));
switch(cl) {
case "input-params":
$('.id').show();
$('.requestDate').hide();
$('.startEndDate').hide();
setParams(button, [["id","id"]]);
break;
case "input-params-location":
$('.id').show();
$('.requestDate').hide();
$('.startEndDate').hide();
setParams(button, [["locationId","id"]]);
break;
case "input-params-openinghours":
$('.id').show();
$('.requestDate').show();
$('.startEndDate').hide();
var myArray = [["locationId","id"],["requestDate","date"]];
setParams(button, myArray);
break;
case "input-params-allocations":
$('.id').hide();
$('.requestDate').hide();
$('.startEndDate').show();
setParams(button, [["startDate","startDate"],["endDate","endDate"],["includeGroupActivities","includeGroupActivities"]]);
break;
case "input-params-allocations-id":
$('.id').show();
$('.requestDate').hide();
$('.startEndDate').show();
setParams(button, [["id","id"],["startDate","startDate"],["endDate","endDate"],["includeGroupActivities","includeGroupActivities"]]);
break;
default:
sendRequest(button)
}
});
});
除我通过这些值的值是数组太
1)
function(){return v;
} undefined
2)
function Array() {[native code]} undefined
中
3)
function (i v)Array.forEach(this
我怎么能传递没有得到额外的值以正确的方式排列?
由于它是一个二维数组,你应该能够得到像这样的'params [0] [0]''的值。这将获得第一个元素的第一个值。所以当你用'params [0] [0]'得到'[['hey','test],['hey1','test1']''时,你会得到值''hey'''。 – wouter140