奇怪的行为,可搜索的JQuery连接排序.需要修复

Strange behavior to searchable JQuery Connected Sortable. Need fix

本文关键字:排序 连接 JQuery 搜索      更新时间:2023-09-26

我使用的是一个连接的可排序,通过asp.net后端在一个按钮单击上保存奇妙。其他功能包括搜索每个列表的能力。在将项目从一个列表拖放到另一个列表之前,这种方法很有效。当我使用JavaScript搜索一个列表中的项时,它仍然认为它是第一个列表的一部分。有人看到这种行为吗?你知道一个可能的修复,使项目永久的一部分,在DOM内拖到列表。此行为在FF, IE, Chrome等

现在我在这个列表上有按钮,将项目从一个列表移动到另一个基于他们被选中,然后点击按钮,然后使用JQuery append()的第二个列表的一部分。这使得该条目成为第二个列表DOM的永久部分,并且能够在该列表中进行搜索。

这就是我的"啊哈"时刻。它在做它应该做的事情寻找项目并显示它如果它不是项目它就不会显示它。但是,当项目使用sortable移动到另一列时,它仍然具有与第一列相同的类。我需要做出改变。

答案如下…http://jsfiddle.net/6jmLvysj/

         $(input)
         .change(function () {
         var filter = $(this).val();
         if (filter) {
             //here is my DAH moment it is looking for this class so when the user was typing in the first search input it was looking for item it would be searching for it is the second column--give myself a Gib slap--
             $(list).find(".ui-state-default:not(:Contains(" + filter + "))").hide();
             $(list).find("ui-state-default:Contains(" + filter + ")").show();
         } else {
             $(list).find(".ui-state-default").show();
         }
         return false;
     })
         .keyup(function () {
         $(this).change();
     });

     //so here is where I changed this code when the user brings the item over then it changes it to the proper respected class depending where the user drops it so it can be searched. 
     stop: function (event, ui) {
         if (ui.item.hasClass("ui-state-default")) {
             ui.item.attr('class', 'ui-state-highlight');
         }
         else {
             ui.item.attr('class', 'ui-state-default');
         }