Framework7 - 搜索栏
描述
Framework 7 允许使用 searchbar 类搜索元素。
搜索栏参数
S.No | 参数 &描述 | 类型 | 默认 |
---|---|---|---|
1 | searchList 搜索列表的 CSS 选择器或 HTML 元素。 |
字符串或 HTML 元素 | - |
2 | searchIn 您可以搜索 CSS 选择器的列表视图元素,也可以通过传递 .item-title、.item-text 类来搜索元素。 |
string | '.item-title' |
3 | found 它使用"found"元素搜索 CSS 选择器或 HTML 元素。此外,如果没有指定元素,它将使用 .searchbar-found 元素。 |
字符串或 HTML 元素 | - |
4 | notfound 它使用"not-found"元素搜索 CSS 选择器或 HTML 元素。此外,如果没有指定元素,它将使用 .searchbar-not-found 元素。 |
字符串或 HTML 元素 | - |
5 | overlay 它使用"searchbar overlay"元素搜索 CSS 选择器或 HTML 元素,如果没有指定元素,它将使用 .searchbar-overlay 元素。 |
字符串或 HTML 元素 | - |
6 | ignore 您可以使用搜索栏。 |
string | '.searchbar-ignore' |
7 | customSearch 启用后,搜索栏将不会搜索由 searchList 指定的任何列表块,并且您将被允许使用自定义搜索功能。 |
boolean | false |
8 | removeDiacritics 搜索元素时,启用此参数可删除变音符号。 |
boolean | false |
9 | hideDividers 如果没有项目,此参数将隐藏项目分隔符和组标题。 |
boolean | true |
10 | hideGroups 如果在列表视图组中未找到任何项目,此参数将隐藏组。 |
boolean | true |
搜索栏回调
S.No | 回调 &描述 | 类型 | 默认 |
---|---|---|---|
1 | onSearch 此方法将在搜索时触发回调函数。 |
函数 (s) | - |
2 | onEnable 此方法将在搜索栏变为活动状态时触发回调函数。 |
函数 (s) | - |
3 | onDisable 当搜索栏处于非活动状态时,此方法将触发回调函数。 |
function (s) | - |
4 | onClear 当您点击"clear"元素时,此方法将触发回调函数。 |
function (s) | - |
搜索栏属性
S.No | 属性和说明 |
---|---|
1 | mySearchbar.params 表示通过对象传递的初始化参数。 |
2 | mySearchbar.query 搜索当前查询。 |
3 | mySearchbar.searchList 定义搜索列表块。 |
4 | mySearchbar.container 使用 HTML 元素定义搜索栏容器。 |
5 | mySearchbar.input 使用 HTML 元素定义搜索栏输入。 |
6 | mySearchbar.active 定义搜索栏是启用还是禁用。 |
搜索栏方法
S.No | 方法 &描述 |
---|---|
1 | mySearchbar.search(query); 此方法搜索传递的查询。 |
2 | mySearchbar.enable(); 启用搜索栏。 |
3 | mySearchbar.disable(); 禁用搜索栏。 |
4 | mySearchbar.clear(); 您可以清除查询并搜索结果。 |
5 | mySearchbar.destroy(); 它会破坏搜索栏实例。 |
搜索栏 JavaScript 事件
S.No | 事件 &描述 | 目标 |
---|---|---|
1 | search 您可以在搜索元素时触发此事件。 |
<div class="list-block"> |
2 | clearSearch 当用户点击 clearSearch 元素时,将触发此事件。 |
<div class="list-block"> |
3 | enableSearch 当搜索栏变为启用时,将触发此事件。 |
<div class="list-block"> |
4 | disableSearch 当搜索栏被禁用,并且用户点击取消按钮或"搜索栏覆盖"元素时,将触发此事件。 |
<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 文件,输出显示如下。
如果在搜索栏中输入了列表中包含的元素,则会显示列表中的特定元素。
如果输入了列表中包含的元素以外的元素,则显示未找到元素。