代码之家  ›  专栏  ›  技术社区  ›  ineersa

选择的多选顺序。加载页面时插件处于活动状态

  •  0
  • ineersa  · 技术社区  · 11 年前

    我不太熟悉jquery,所以不要太严格。任务是在Chosen multiselect插件中排序。 以下是解决方法:

    $(function(){
            $("select#Books_id_author").each(function(){
                if($(this).data("order")==true){
                    $(this).val('');
                    $(this).chosen();
                    var $ordered = $('[name="_'+jQuery(this).attr('id')+'"]');
                    var selected = $ordered.val().split(',');
                    var chosen_object = $(this).data('chosen');
                    $.each(selected, function(index, item){
                        $.each(chosen_object.results_data, function(i, data){
                            if(data.value == item){
                                $("#"+data.dom_id).trigger('mouseup');
                            }
                        });
                    });
                    $(this).data("backupVal",$(this).val());
                    $(this).change(function(){
                        var backup = $(this).data("backupVal");
                        var current = $(this).val();
                        if(backup == null){
                            backup = [];
                        }
                        if(current == null){
                            current = [];
                        }
                        if(backup.length > current.length){
                            $.each(backup, function(index, item) {
                                if($.inArray(item, current) < 0){
                                    for(var i=0; i<selected.length; i++){
                                        if(selected[i] == item){
                                            selected.splice(i,1);
                                        }
                                    }
                                }
                            });
                        }else if(backup.length < current.length){
                            $.each(current, function(index, item) {
                                if($.inArray(item, backup) < 0){
                                    selected.push(item);
                                }
                            });
                        }
                        $ordered.val(selected.join(','));
                        $(this).data("backupVal",current);
                    });
                }else{
                    $(this).chosen();
                }
            });
        });
    

    问题是,该插件在页面加载后处于活动状态(我想这是因为触发器('useup')),显示结果下降。

    《选择》中是否有任何触发因素使其不活跃,或者可能是其他原因。 谢谢

    1 回复  |  直到 11 年前
        1
  •  0
  •   ineersa    11 年前

    通过为所选对象编写订单插件解决了问题。