2
這可能是由於我是JavaScript新手,而我只是不知道正確的語法,但無法讓我的主幹模型屬性設置在此上使用當前語法刪除事件。有什麼建議麼?我已經使用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);
你是對的jakee。真棒!一切工作都應該如此!對於任何人使用這篇文章作爲資源,我在「目標」變量中的每個值都包含一個冒號,在遵循jakee指令時需要將其刪除。感謝jakee! – ac360
你也可以'preflist.set(dataattribute,datavalue)'因爲[「你也可以傳遞個別鍵和值」](http://backbonejs.org/#Model-set)。 –
優點,不得不走的艱難路! – jakee