我有兩個可排序的列表鏈接在一起。將項目移動到新的可排序:如何引用列表我將元素放到?
我有第一個列表上的事件偵聽器調用「sortupdate」上的函數「A」,當我排序列表中的項目或從另一個列表中接收項目時執行一些功能。
我還有第二個列表上的事件監聽器調用「sortreceive」上的函數「B」,以便在從另一個列表中收到一個項目時執行一些功能。
我的問題是,無論何時將列表1中的內容移動到列表2,函數「A」也會被調用,從而導致我的代碼中出現錯誤。我想在函數「A」的開頭添加一個'if'子句,只有當第一個列表是目標時才運行這個代碼,但是我不知道如何引用目標。
或者有更好的方法來檢查一個項目是否被拖出這個列表?
/*添加當前的代碼*/
$("#divMainMenu").bind("sortupdate", function(event, ui)
{ dropRootCategory(event,ui);})//when the main menu receives a menu item
$("ul.divSubMenu ").bind("sortreceive", function(event, ui)
{ dropSubMenu(event, ui);})//when the main submenu receives a menu item
function dropRootCategory(event, ui)
{/*item dropped on root category*/
//do some different stuff
}
function dropSubCategory(event, ui)
{//item dropped on a sub submenu
//do some stuff
}
我已經試過檢查目標:
if (event.target.id == 'divMainMenu') { //
不因爲目標ID保持 'divMainMenu' 不管我在哪裏工作下降到。
下一個我試圖檢查發件人:
if (ui.sender == 'null'){//
不過,這僅與任何信息填充後,通過sortupdate階段過去了,到了sortreceive,所以它再次引發了代碼運行。
/* ** * ** *下面的答案 每秒更新Keith的想法,我回答了這個用下面的代碼: 在菜單開始,我添加了一個變量保存長度
if ($('#divMainMenu').children().length >= numMenuItems){
//do some stuff
}
:主菜單
var numMenuItems = $('#divMainMenu').children().length;
然後我if語句的原始長度0
再次感謝Keith!我要去堅果這一個:)
我們可以看到你到目前爲止嘗試過嗎? –
剛剛更新了一些更多的信息。謝謝基思。 –