Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如果项目';s的兄弟姐妹没有类(在mixitup插件中)?_Jquery_Variables - Fatal编程技术网

Jquery 如果项目';s的兄弟姐妹没有类(在mixitup插件中)?

Jquery 如果项目';s的兄弟姐妹没有类(在mixitup插件中)?,jquery,variables,Jquery,Variables,我知道,您可以使用以下命令指定项目是否没有类: if (!$(this).hasClass("test")) { 这很好,但我无法确定在代码中的何处使用它。我使用mixitupjquery插件进行过滤,整个过程中有一些if条件。我想说的是,如果$t('[data filter=“all”]的兄弟姐妹中没有一个类为“active”,那么将该类应用于$t,并将变量filterString设置为“all” 我希望,这样做的效果是,如果您删除所有过滤器,它会将其设置回默认的“全部”过滤器。请参见以下内

我知道,您可以使用以下命令指定项目是否没有类:

if (!$(this).hasClass("test")) {
这很好,但我无法确定在代码中的何处使用它。我使用mixitupjquery插件进行过滤,整个过程中有一些if条件。我想说的是,如果
$t('[data filter=“all”]
的兄弟姐妹中没有一个类为“active”,那么将该类应用于
$t
,并将变量filterString设置为“all”

我希望,这样做的效果是,如果您删除所有过滤器,它会将其设置回默认的“全部”过滤器。请参见以下内容:

// INSTANTIATE MIXITUP

$('#equipment-grid').mixitup({
    //layoutMode: 'list', // Start in list mode (display: block) by default
    //listClass: 'list', // Container class for when in list mode
    //gridClass: 'grid', // Container class for when in grid mode
    effects: ['fade', 'blur'], // List of effects 
    //listEffects: ['fade','rotateX'] // List of effects ONLY for list mode
});

// HANDLE MULTI-DIMENSIONAL CHECKBOX FILTERING

/*  
 *  We can't used the default multiFilter because it
 *   behaves differently to what is required here.
 */

var $filters = $('#filters').find('li');
var filterString = 'all';

// Bind checkbox click handlers:

$filters.on('click', function () {
    var $t = $(this),
        filter = $t.attr('data-filter');

    if (filter == 'all') {
        // If "all"
        if (!$t.hasClass('active')) {
            // if unchecked, check "all" and uncheck all other active filters
            $t.addClass('active').siblings().removeClass('active');
            // Replace entire string with "all"
            filterString = 'all';
        }
    } else {
        // Else, uncheck "all"
        $t.siblings('[data-filter="all"]').removeClass('active');
        // Remove "all" from string
        filterString = filterString.replace('all', '');
        if (!$t.hasClass('active')) {
            // Check checkbox
            $t.addClass('active');
            // Append filter to string
            filterString = filterString == '' ? filter : filterString + ' ' + filter;
        } else {
            // Uncheck
            $t.removeClass('active');
            // Remove filter and preceeding space from string with RegEx
            var re = new RegExp('(\\s|^)' + filter);
            filterString = filterString.replace(re, '');
        };
    };

    /*
     *  We then send these strings to MixItUp using the filter method. We can send as
     *  many dimensions to MixitUp as we need using an array as the second argument
     *  of the "filter" method. Each dimension must be a space seperated string.
     */

    $('#equipment-grid').mixitup('filter', [filterString])
});
像这样的

// if we're left with nothing selected, check 'All' again
if ($filters.filter('.active').size() == 0) {
    $filters.filter('[data-filter="all"]').addClass('active');
    filterString = 'all';
}
这将在您完成所有其他复选框处理之后,但在您调用
mixitup()
之前,立即进入您的代码中。因此,就在您的注释块上方


基本上,一旦我们完成了所有的处理,我们会查看
$filters
中的所有元素,如果没有匹配
.active
,那么我们会找到all过滤器,并将活动类添加到该过滤器中。注意,此时,我们不关心刚才单击的是哪一个。我们不会在此处引用
$t
l、

这看起来不错,谢谢@jcsanyi。但是,在我的脚本中,这会放在哪里?在前面的if/else语句之后?用新的答案更新,它会放在哪里。