这可能是因为我是 javascript 新手,我只是不知道正确的语法,但我无法使用当前语法在此 Drop Event 上设置我的主干模型属性。有什么建议么?我已经使用 handleDrop 进行了一些测试,并且能够设置和保存模型实例,但不能使用 handleDrop 函数中的当前代码。
其他关于更有效的写作方式的建议总是受欢迎的:)
//Set the data contained by the draggable elements
var sourceID;
var payloads = {
poolpricedraggable: "poolprice",
nonedraggable: "none"
};
//Set the data contained in the droppable elements
var targetID;
var targets = {
panelone: "panel_one:",
paneltwo: "panel_two:",
panelthree: "panel_three:",
panelfour: "panel_four:",
panelfive: "panel_five:",
panelsix: "panel_six:"
}
//Create variable for all draggable & droppable elements
var element = function(id) { return document.getElementById(id); }
//Create event handlers for all drag and drop events
function handleDragStart(event) {
sourceID = this.id;
}
function handleDrop(event) {
if(event.preventDefault) event.preventDefault();
targetID = this.id;
var dataattribute = targets[targetID];
var datavalue = payloads[sourceID];
var data = dataattribute + " " + datavalue;
preflist.set(data);
preflist.save();
}
//Add listeners for those events to the correct dashboard elements
element('poolpricedraggable').addEventListener('dragstart', handleDragStart, false);
element('panelone').addEventListener('drop', handleDrop, false);
element('paneltwo').addEventListener('drop', handleDrop, false);
element('panelthree').addEventListener('drop', handleDrop, false);
element('panelfour').addEventListener('drop', handleDrop, false);
element('panelfive').addEventListener('drop', handleDrop, false);
element('panelsix').addEventListener('drop', handleDrop, false);