在JPList库中对“ OR”而不是“ AND”进行排序

时间:2019-01-25 09:44:39

标签: jquery html css sorting jplist

我正在尝试使用JPList对多个项目进行排序。当前,JPList搜索类似于“ AND”(例如,对具有标签,html,php和jQuery的项目进行排序),但我想过滤包含这些标签的所有项目(例如,对包含html,php的所有项目进行排序或jQuery)。有启用此功能的选项吗?

或者有人知道没有JPlist的方法吗?

下面是代码(注意:这是JPlist中的默认代码。您可以在此处查看:https://www.jplist.org/documentation/controls/checkbox-path-filter):

<h1><a href="https://jplist.org/documentation/controls/checkbox-path-filter">jPList Checkbox Path Filter Control</a></h1>

<div class="box">

    <!-- checkbox path filter control -->
    <label>
        <input
            type="checkbox"
            data-jplist-control="checkbox-path-filter"
            data-path=".title"
            data-group="data-group-1"
            name="name1"
            checked />
        Filter by Title
    </label>

    <!-- checkbox path filter control -->
    <label>
        <input
            type="checkbox"
            data-jplist-control="checkbox-path-filter"
            data-path=".views"
            data-group="data-group-1"
            name="name2" />
         Filter by Views
    </label>

    <!-- checkbox path filter control -->
    <label>
        <input
            type="checkbox"
            data-jplist-control="checkbox-path-filter"
            data-path=".likes"
            data-group="data-group-1"
            name="name3" />
        Filter by Likes
    </label>

</div>

<!-- content to filter -->
<div data-jplist-group="data-group-1">

    <!-- item -->
    <div data-jplist-item>
        <div class="views likes">Views value + Likes value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="views title">Views value + title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title likes">Title value  + likes value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="likes">Likes value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="likes">Likes value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="title">Title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="views title">Views value + title value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="likes">Likes value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="views">Views value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="likes">Likes value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="views">Views value</div>
    </div>

    <!-- item -->
    <div data-jplist-item>
        <div class="views likes">Views value + likes value</div>
    </div>
</div>

<style>
html, body{
    background: #efefef;  
    box-sizing: border-box;
    padding: 10px;
}

h1{
    text-align: center;
    margin: 0 0 10px 0;
    padding: 0;
    font-size: 22px;
    color: #212529;
}

a{
    color: #212529;
}

a:hover{
  text-decoration: none;
}


[data-jplist-group]{
    display: flex;
    font-size: 16px;
    flex-wrap: nowrap;
    flex-direction: column;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

[data-jplist-item]{
  border-bottom: 1px dotted #ccc;
  width: 100%;
  text-align: center;
  padding: 10px 0;
  box-sizing: border-box;
}

.box{
  display: flex;
  justify-content: center;
  margin: 20px 0;
}

label{
    display: inline-block;
    margin: 0 10px;
}
</style>

<script>
jplist.init();
</script>

这是JPlist上的一个有效的Codepen演示:https://codepen.io/1rosehip/pen/RyYrJG

1 个答案:

答案 0 :(得分:1)

在复选框组的所有组中添加属性data-or="example"

例如:

<div class="box">

    <!-- checkbox path filter control -->
    <label>
        <input
            type="checkbox"
            data-jplist-control="checkbox-path-filter"
            data-path=".title"
            data-group="data-group-1"
            name="name1"
            data-or="example" 
            checked />
        Filter by Title
    </label>

    <!-- checkbox path filter control -->
    <label>
        <input
            type="checkbox"
            data-jplist-control="checkbox-path-filter"
            data-path=".views"
            data-group="data-group-1"
            name="name2" 
            data-or="example"/>
         Filter by Views
    </label>

    <!-- checkbox path filter control -->
    <label>
        <input
            type="checkbox"
            data-jplist-control="checkbox-path-filter"
            data-path=".likes"
            data-group="data-group-1"
            name="name3"
            data-or="example"/>
        Filter by Likes
    </label>

</div>

对我有用!