我的应用程序的基本概念是将一组托盘映射到卡车上。我有一个页面,允许用户拖动可拖动的 div“托盘”并将其放置在卡车上的可放置 div“插槽”中。每行、左右列的重量和卡车总重量都是即时计算的。然后,我将所有信息传递到一个页面以打印托盘和槽位表,以便操作员可以装载卡车。如果用户只装载了一半的卡车然后想稍后再回来完成,那么问题就在于恢复负载。我知道如何保存任意数量的数据点,但是当我重建页面时,我找不到将“托盘”放回其“插槽”的方法。
这是托盘的 div,一些插槽和放置过程(我不确定还需要什么)
//load the playpen with the pallets that belong on this truck
for (var i = 0; i < noPallets; i++) {
$('<div id="' + PalletIDs[i] + '">' + PalletIDs[i] + '<br>' + Storage[i] + ':' + Weights[i] + '</div>').data('pallet',
{ ID: PalletIDs[i], Weight: Weights[i], columnNo: 0, rowNo: 0, tierNo:0 }).appendTo('#playpen').draggable({
containment: '#content',
stack: '#playpen div',
cursor: 'move',
start: handlePalletStart,
revert: true
});
}
// Create the pallet slots for truck left
var words = ['C<br>one', 'C<br>two', 'C<br>three', 'C<br>four', 'C<br>five', 'C<br>six', 'C<br>seven', 'C<br>eight', 'C<br>nine', 'C<br>ten', 'C<br>eleven'];
for (var i = 1; i <= 11; i++) {
position = 1000 + (i * 10) + 3
$('<div id="' + position + '">' + words[i - 1] + '</div>').data('position', { columnNo: 1, rowNo: i, tierNo: 3 }).appendTo('#truckleftC').droppable({
accept: '#playpen div',
hoverClass: 'hovered',
drop: handlePalletDrop
});
}
function handlePalletDrop(event, ui) {
// this is the truck location we are about to drop into
var columnNo = $(this).data('position').columnNo;
var rowNo = $(this).data('position').rowNo;
var tierNo = $(this).data('position').tierNo;
// this is pallet information
var palletID = ui.draggable.data('pallet').ID;
var weight = ui.draggable.data('pallet').Weight;
// if the pallet was already in a positio, we need to zero that position
if (ui.draggable.data('pallet').columnNo != 0) {
oldposition = ui.draggable.data('pallet').columnNo * 1000 + ui.draggable.data('pallet').rowNo * 10 + ui.draggable.data('pallet').tierNo;
// alert(oldposition);
for (var h = 0; h <= 65; h++) {
if (aryTWeight[h][0] == oldposition) {
aryTWeight[h][1] = 0;
}
}
}
// set the position in the truck for this pallet
ui.draggable.data('pallet').columnNo = columnNo;
ui.draggable.data('pallet').rowNo = rowNo;
ui.draggable.data('pallet').tierNo = tierNo;
// set the weight for this position in the truck
position = columnNo * 1000 + rowNo * 10 + tierNo
// alert(position);
for (var h = 0; h <= 65; h++) {
if (aryTWeight[h][0] == position) {
aryTWeight[h][1] = weight;
}
}
// alert(columnNo + ' : ' + rowNo + ' : ' + tierNo);
// set the hidden text box with the palletid so data can be posted to next page
for (var i = 0; i < document.forms[0].elements.length; i++) {
element = document.forms[0].elements[i];
if (element.name == oldposition) {
element.value = 0;
};
if (element.name == position) {
element.value = palletID;
};
}
// set all of the weights for rows, columns and totals
calcWeights();
ui.draggable.addClass('correct');
ui.draggable.position({ of: $(this), my: 'left top', at: 'left top' });
ui.draggable.draggable('option', 'revert', false);
}