【发布时间】:2015-12-18 04:15:46
【问题描述】:
我有一个显示仓库内具有多个位置的特定商品的库存信息的模式。用户从每个菜单中选择位置和数量并单击确认,然后需要将该模式中的信息导入到打印输出的选择列表中。
为此,我计划使用数组将数据传输到选择列表。
每一行都有一个隐藏字段,包含位置的值和从那里挑选的数量。
位置 1 + 数量 1 = 隐藏字段 1
位置 2 + 数量 2 = 隐藏字段 2
我现在希望能够在单击按钮后将这些隐藏字段放入数组中。
隐藏字段 1 + 隐藏字段 2 = 数组。
我可以很好地创建隐藏字段,当我制作包含所有数据的最终数组时,它似乎只想将要创建的最新隐藏字段添加到其中。
对话框 - 选择数量按钮(用于确认选择):
//PICK QUANTITY Button
'Pick Quantity': function() {
jQuery('.ui-dialog button:nth-child(1)').button('disable');
//Disables the current selection, so that it cannot be editted
$('#AddLocQtyPick'+Picker).prop ('disabled', true);
//Disables the current selection, so that it cannot be editted
$('#LocationPickerSelect'+ Picker).prop ('disabled', true);
//Adds Unique Number to the ID of the input fields
Picker++;
//For Loop that helps to total up the quanities being selected in each picker
total=0;
for (i = 0; i<Picker; i++) {
total= total + $('#AddLocQtyPick'+i).val() * 1.0;
}
//Variable decides max value of pick on appends using previous selection
QtyReqTot= QtyReq - total;
//"Pick Another location" button is enabled whilst Qty Req has not been met
if (total !== QtyReq){
jQuery('.ui-dialog button:nth-child(2)').button('enable');
}
//"Pick Quantity", "Pick Another Location" are disabled, whilst "Confirm" button is enabled when total reaches Qty Req
if (total == QtyReq){
jQuery('.ui-dialog button:nth-child(2)').button('disable');
jQuery('.ui-dialog button:nth-child(1)').button('disable');
jQuery('.ui-dialog button:nth-child(3)').button('enable');
}
//Pick Another Location button is disabled if no more locations to pick from
if (length == 1){
jQuery('.ui-dialog button:nth-child(2)').button('disable');
}
if (total !== QtyReq && length == 1){
jQuery('.ui-dialog button:nth-child(1)').button('disable');
$(":button:contains('Cancel')").focus();
}
//Create Hidden Field - Location
//for loop that creates the fields
for (i = 0; i<Picker; i++){
HiddenSelection = [$('#LocationPickerSelect'+i).val(),$('#AddLocQtyPick'+i).val()];
var appendHiddenSelection = '<input type="hidden" class="HiddenSelection'+ i +'" value='+HiddenSelection+'>';
$('#AddLocationPicker').append(appendHiddenSelection);
alert(appendHiddenSelection +'This is SelectionField'+i);
}
},
确认按钮 - 用于生成包含先前数组的最终数组:
'Confirm': function() {
//Reset the length loop
length = undefined;
//Remove "Multiple Location" icon from the row.
$('#icon'+id).hide();
//Checks "Multiple Location" icon for existence and adds Pick List button when all hidden.
$('img[id^=icon]:visible').length || $('#ProcessPickList').show();
//Change text colour back to blue to have visual confirmation that item is ready for picking
$('#Desc'+id).css('color', '#0000FF');
$('#QtyReq'+id).css('color', '#0000FF');
$('#QtyinStock'+id).css('color', '#0000FF');
//Create Total Array
TotalHiddenArray = [HiddenSelection]
alert (TotalHiddenArray);
$(this).dialog('close');
},
我认为我需要能够为输入字段创建唯一的 IDS,并展示如何将它们全部添加到数组中。
【问题讨论】:
-
“
TotalHiddenArray = [HiddenArray]”。HiddenArray的声明和(可能)填写在哪里?你能让你的代码更清晰一点吗? -
@NaijaProgrammer 抱歉,我现在稍微更改了代码,并编辑了我的问题。用于数组的变量在“Pick Quantity”部分中声明。
-
到底是什么问题,您的代码的哪一部分有问题。是否可以将其简化为该部分?顺便说一句,
HiddenSelection是一个数组,您将其设置为表单输入字段的值。这对你有什么作用? -
模式获取 Location 和 Qty 的值并将它们放在隐藏字段中。它对存在的每一行都执行此操作。然后,我想获取所有这些隐藏字段(每行生成 1 个)并将它们放入一个数组中。但是,当我尝试这样做时,该数组仅包含创建的最后一个隐藏字段。我想我需要让每个隐藏字段都有一个唯一的 id,然后在创建数组时循环遍历所有字段并将它们添加到数组中?
-
你必须看看 Edensource 发布的答案。这应该可以解决您的问题。
标签: javascript php jquery arrays hidden-field