te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>html - How to display 'no result found' on search when there is no result found, using javascript and list.js -
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How to display 'no result found' on search when there is no result found, using javascript and list.js -

programmeradmin3浏览0评论

How do i display NO RESULT FOUND after user has searched for something that is not in the list. I am using list.js and i cant figure out how to implement that?

Is there is a way i can add a JavaScript code somewhere on my code that can monitor when the table list is empty and display no result found as i search using list.js OR a better alternative?

I need a way i could tell my users that what they are searching for is not there.

var monkeyList = new List('users', {
  valueNames: ['name', 'born'],
  page: 3,
  plugins: [ ListPagination({}) ] 
});
<div id="users">
  <input class="search" placeholder="Search" />
  <button class="sort" data-sort="name">
    Sort by name
  </button>

  <ul class="list">
    <li>
      <h3 class="name">Jonny Stromberg</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Jonas Arnklint</h3>
      <p class="born">1985</p>
    </li>
    <li>
      <h3 class="name">Martina Elm</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Gustaf Lindqvist</h3>
      <p class="born">1983</p>
    </li>
  </ul>
<ul class="pagination"></ul>
</div>


<script src=".js"></script> 
<script src=".pagination.js"></script>
<script src=".10.1/jquery.min.js"></script>

How do i display NO RESULT FOUND after user has searched for something that is not in the list. I am using list.js and i cant figure out how to implement that?

Is there is a way i can add a JavaScript code somewhere on my code that can monitor when the table list is empty and display no result found as i search using list.js OR a better alternative?

I need a way i could tell my users that what they are searching for is not there.

var monkeyList = new List('users', {
  valueNames: ['name', 'born'],
  page: 3,
  plugins: [ ListPagination({}) ] 
});
<div id="users">
  <input class="search" placeholder="Search" />
  <button class="sort" data-sort="name">
    Sort by name
  </button>

  <ul class="list">
    <li>
      <h3 class="name">Jonny Stromberg</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Jonas Arnklint</h3>
      <p class="born">1985</p>
    </li>
    <li>
      <h3 class="name">Martina Elm</h3>
      <p class="born">1986</p>
    </li>
    <li>
      <h3 class="name">Gustaf Lindqvist</h3>
      <p class="born">1983</p>
    </li>
  </ul>
<ul class="pagination"></ul>
</div>


<script src="http://listjs./no-cdn/list.js"></script> 
<script src="http://listjs./no-cdn/list.pagination.js"></script>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.10.1/jquery.min.js"></script>

Share Improve this question edited Feb 28, 2016 at 13:32 Omari Victor Omosa asked Feb 28, 2016 at 9:46 Omari Victor OmosaOmari Victor Omosa 2,8794 gold badges26 silver badges51 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Added this to the HTML:

<div class="not-found" style="display:none">Not Found</div>

It will be displayed when no matching list element is found.


Attached this event listener to listen for changes in the search box:

$('.search').on('keyup', function(event) { // Fired on 'keyup' event

  if($('.list').children().length === 0) { // Checking if list is empty

    $('.not-found').css('display', 'block'); // Display the Not Found message

  } else {

    $('.not-found').css('display', 'none'); // Hide the Not Found message

  }
});

You can also use the searchComplete callback (v1.5.0) like this:

monkeyList.on('searchComplete', function (e) {

  if (e.matchingItems.length == 0) {

    // NO RESULTS
    // jquery
    $('.not-found').show();
    // vanilla
    // by classname
    document.getElementsByClassName('className')[0].style.display = "block";
    // or by ID
    document.getElementById("elementID").style.display = "block";

  } else {

    $('.not-found').hide();
    document.getElementsByClassName('className')[0].style.display = "none";
    document.getElementById("elementID").style.display = "none";

  }

});

Hope this helps!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论