Framework7 - 搜索栏


描述

Framework 7 允许使用searchbar类搜索元素。

搜索栏参数

序列号 参数及说明 类型 默认
1

搜索列表

它搜索列表的 CSS 选择器或 HTML 元素。

字符串或 HTML 元素 -
2

搜索

您可以搜索 CSS 选择器的列表视图元素,也可以通过传递.item-title.item-text类来搜索元素。

细绳 '.项目标题'
3

成立

它使用“found”元素搜索 CSS 选择器或 HTML 元素。此外,如果没有指定元素,它会使用.searchbar-found元素。

字符串或 HTML 元素 -
4

未找到

它使用“not-found”元素搜索 CSS 选择器或 HTML 元素。此外,如果没有指定元素,它会使用.searchbar-not-found元素。

字符串或 HTML 元素 -
5

覆盖

它使用“searchbar overlay”元素搜索 CSS 选择器或 HTML 元素,如果没有指定元素,则使用.searchbar-overlay元素。

字符串或 HTML 元素 -
6

忽略

您可以使用搜索栏忽略项目的 CSS 选择器。

细绳 '.searchbar-忽略'
7

自定义搜索

启用后,搜索栏将不会搜索由searchList指定的任何列表块,并且您将被允许使用自定义搜索功能。

布尔值 错误的
8

删除变音符号

搜索元素时,通过启用此参数删除变音符号。

布尔值 错误的
9

隐藏分隔线

如果没有项目,此参数将隐藏项目分隔符和组标题。

布尔值 真的
10

隐藏组

如果列表视图组中没有找到任何项目,此参数将隐藏组。

布尔值 真的

搜索栏回调

序列号 回调和描述 类型 默认
1

搜索上

该方法将在搜索时触发回调函数。

功能) -
2

启用

当搜索栏激活时,此方法将触发回调函数。

功能) -
3

禁用

当搜索栏变为非活动状态时,此方法将触发回调函数。

功能) -
4

清除

当您单击“清除”元素时,此方法将触发回调函数。

功能) -

搜索栏属性

序列号 属性及说明
1

mySearchbar.params

表示随对象传递的初始化参数。

2

mySearchbar.query

搜索当前查询。

3

mySearchbar.searchList

定义搜索列表块。

4

mySearchbar.container

使用 HTML 元素定义搜索栏容器。

5

mySearchbar.input

使用 HTML 元素定义搜索栏输入。

6

mySearchbar.active

它定义搜索栏是启用还是禁用。

搜索栏方法

序列号 方法与说明
1

mySearchbar.search(查询);

此方法搜索传递的查询。

2

mySearchbar.enable();

它启用搜索栏。

3

mySearchbar.disable();

它禁用搜索栏。

4

mySearchbar.clear();

您可以清除查询和搜索结果。

5

mySearchbar.destroy();

它会破坏搜索栏实例。

搜索栏 JavaScript 事件

序列号 活动及描述 目标
1

搜索

您可以在搜索元素时触发此事件。

<div class="list-block">
2

清除搜索

当用户单击clearSearch 元素时,将触发此事件。

<div class="list-block">
3

启用搜索

当搜索栏启用时,该事件将被触发。

<div class="list-block">
4

禁用搜索

当搜索栏被禁用并且用户单击取消按钮或“搜索栏覆盖”元素时,将触发此事件。

<div class="list-block">

例子

以下示例演示了 Framework7 中滚动搜索栏的使用 -

<!DOCTYPE html>
<html>

   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, 
         maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
      <meta name = "apple-mobile-web-app-capable" content = "yes" />
      <meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
      <title>Search Bar Layout</title>
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
   </head>

   <body>
      <div class = "views">
         <div class = "view view-main">
            <div class = "pages navbar-fixed">
               <div data-page = "home" class = "page">
               
                  <div class = "navbar">
                     <div class = "navbar-inner">
                        <div class = "center sliding">Search Bar Layout</div>
                     </div>
                  </div>
                  
                  <form data-search-list = ".list-block-search" data-search-in = ".item-title" 
                     class = "searchbar searchbar-init">
                     <div class = "searchbar-input">
                        <input type = "search" placeholder = "Search"><a href = "#" 
                           class = "searchbar-clear"></a>
                     </div>
                     <a href = "#" class = "searchbar-cancel">Cancel</a>
                  </form>
                  
                  <div class = "searchbar-overlay"></div>
                  
                  <div class = "page-content">
                     <div class = "content-block searchbar-not-found">
                        <div class = "content-block-inner">No element found...</div>
                     </div>
                     
                     <div class = "list-block list-block-search searchbar-found">
                        <ul>
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">India</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Argentina</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Belgium</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Brazil</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Canada</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Colombia</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Denmark</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Ecuador</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">France</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Germany</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Greece</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Haiti</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Hong Kong</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Iceland</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Ireland</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Jamaica</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Japan</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Kenya</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Kuwait</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Libya</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Liberia</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Malaysia</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Mauritius</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Mexico</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Namibia</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">New Zealand</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Oman</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Paraguay</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Philippines</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Russia</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Singapore</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">South Africa</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Thailand</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">United Kingdom</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Vatican City</div>
                              </div>
                           </li>
                           
                           <li class = "item-content">
                              <div class = "item-inner">
                                 <div class = "item-title">Zimbabwe</div>
                              </div>
                           </li>
                        </ul>
                     </div>
                     
                  </div>
               </div>
            </div>
         </div>
      </div>
      
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>
      
      <script>
         var myApp = new Framework7();
         var mainView = myApp.addView('.view-main');
      </script>
   </body>

</html>

输出

让我们执行以下步骤来看看上面给出的代码是如何工作的 -

  • 将上面给出的 HTML 代码search_bar.html文件保存在服务器根文件夹中。

  • 以 http://localhost/search_bar.html 打开此 HTML 文件,输出如下所示。

  • 如果在搜索栏中输入列表中包含的元素,则会显示列表中的该特定元素。

  • 如果输入了列表中包含的元素以外的元素,则显示未找到元素。