搜索栏允许用户在列表元素中搜索,或者它可以用来作为UI组件,放到你自己的搜索实现中。
搜索栏布局
搜索栏应该放到“.page”内,“.page-content”前:
- <div class="page">
- <!-- Search bar -->
- <form class="searchbar">
- <div class="searchbar-input">
- <input type="search" placeholder="Search">
- <a href="#" class="searchbar-clear"></a>
- </div>
- <a href="#" class="searchbar-cancel">Cancel</a>
- </form>
- <!-- Search bar overlay-->
- <div class="searchbar-overlay"></div>
- <!-- Page content -->
- <div class="page-content">
- <div class="content-block searchbar-not-found">
- Nothing found
- </div>
- <div class="list-block list-block-search searchbar-found">
- <ul>
- ... list view items ...
- </ul>
- </div>
- </div>
- </div>
其中:
-
form class="searchbar"
- 主要的搜索栏容器。它不必是个form元素,但推荐如此。-
div class="searchbar-input"
- 搜索区域和取消按钮的容器-
input type="search"
- search field -
a class="searchbar-clear"
- button to clear field value and reset search results. Optional element
-
-
a class="searchbar-cancel"
- searchbar Cancel button that will deactivate searchbar, reset search results and clear search field. Optional element
-
-
div class="searchbar-overlay"
- Add this element right after search bar to enable dark overlay over page content when search bar is active. Optional element. -
"list-block-search"
- list block where we are going to search elements. -
"searchbar-found"
- element with this class will be displayed if searchbar find elements that match to search query. Visible by default. Optional element. -
"searchbar-not-found"
- element with this class will be displayed if searchbar doesn't find elements that match to search query. Hidden by default. Optional element.
Initialize Searchbar with JavaScript
Now, when we have Searchbar' HTML, we need to initialize it. We need to use related App's method:
myApp.searchbar(searchbarContainer, parameters) - initialize searchbar with options
- searchbarContainer - HTMLElement or string (with CSS Selector) of Searchbar container HTML element. Required.
- parameters - object - object with Searchbar parameters. Optional.
- Method returns initialized Searchbar instance
For example:
- var mySearchbar = app.searchbar('.searchbar', {
- searchList: '.list-block-search',
- searchIn: '.item-title'
- });
Searchbar Parameters
Let's look on list of all available parameters:
searchList | string or HTMLElement | CSS selector or HTML element of list block to search | |
searchIn | string | '.item-title' | CSS selector of List View element's field where we need to search. Usually we search through element titles ('.item-title'). It is also to pass few elements for search like '.item-title, .item-text' |
found | string or HTMLElement | CSS selector or HTMLElement of searchbar "found" element. If not specified, searchbar will look for .searchbar-found element on page |
|
notFoud | string or HTMLElement | CSS selector or HTMLElement of searchbar "not-found" element. If not specified, searchbar will look for .searchbar-not-found element on page |
|
overlay | string or HTMLElement | CSS selector or HTMLElement of searchbar overlay. If not specified, searchbar will look for .searchbar-overlay element on page |
|
ignore | string | '.searchbar-ignore' | CSS selector for items to be ignored by searchbar and always present in search results |
customSearch | boolean | false | When enabled searchbar will not search through any of list blocks specified by `searchList` and you will be able to use custom search functionality, for example, for calling external APIs with search results and for displaying them manually |
removeDiacritics | boolean | false | Enable to remove/replace diacritics (á, í, ó, etc.) during search |
hideDividers | boolean | true | If enabled, then search will consider item dividers and group titles and hide them if there are no found items right after them |
hideGroups | boolean | true | If enabled, then search will consider list view groups hide them if there are no found items inside of these groups |
onSearch | function (s) | Callback function will be triggered during search (search field change). | |
onEnable | function (s) | Callback will be triggered when Search Bar becomes active | |
onDisable | function (s) | Callback will be triggered when Search Bar becomes inactive - when user clicks on "Cancel" button or on "searchbar-overlay" element | |
onClear | function (s) | Callback will be triggered when user clicks on Search Bar's "clear" element |
Searchbar Methods & Properties
After we initialize Searchbar we have its initialized instance in variable (like mySearchbar
variable in example above) with helpful methods and properties:
mySearchbar.params | Object with passed initialization parameters |
mySearchbar.query | Current search query (search input value) |
mySearchbar.searchList | Dom7 element with search list block. |
mySearchbar.container | Dom7 element with searchbar container HTML element. |
mySearchbar.input | Dom7 element with searchbar input HTML element |
mySearchbar.active | Boolean value that represents is searchbar enabled or disabled |
mySearchbar.search(query); | Force searchbar to search passed query |
mySearchbar.enable(); | Enable/activate searchbar |
mySearchbar.disable(); | Disable/deactivate searchbar |
mySearchbar.clear(); | Clear search query and update results |
mySearchbar.destroy(); | Destroy searchbar instance |
Initialize Searchbar with HTML
If you don't need to use Searchbar methods and properties you can initialize it using HTML without JavaScript. You can do that just by adding additional "searchbar-init" class to .searchbar
. In this case we may pass required parameters using data- attributes.
- <div class="page">
- <!-- Search bar with "searchbar-init" class for auto initialization -->
- <form class="searchbar searchbar-init" data-search-list=".list-block-search" data-search-in=".item-title" data-found=".searchbar-found" data-not-found=".searchbar-not-found">
- <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">
- Nothing found
- </div>
- <div class="list-block list-block-search searchbar-found">
- <ul>
- ... list view items ...
- </ul>
- </div>
- </div>
- </div>
Parameters that used in camelCase, for example searchList, in data- attributes should be used as hypens-case as data-search-list
Access to Searchbar's Instance
If you initialize Searchbar using HTML it is still possible to access to Searchbar's instance. It is "f7Searchbar" property of searchbar's container HTML element:
- var mySearchbar = $$('.searchbar')[0].f7Searchbar;
- // Now you can use it
- mySearchbar.search('Hello world');
Search Bar Example
In this example we use searchbar with auto initialization
- <div data-page="home" class="page">
- <!-- Search bar -->
- <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>
- <!-- Search bar overlay -->
- <div class="searchbar-overlay"></div>
- <div class="page-content">
- <!-- This block will be displayed if nothing found -->
- <div class="content-block searchbar-not-found">
- <div class="content-block-inner">Nothing found</div>
- </div>
- <!-- This block will be displayed if anything found, and this list block is used a searbar target -->
- <div class="list-block list-block-search searchbar-found">
- <ul>
- <li class="item-content">
- <div class="item-inner">
- <div class="item-title">Acura </div>
- </div>
- </li>
- <li class="item-content">
- <div class="item-inner">
- <div class="item-title">Audi</div>
- </div>
- </li>
- ...
- </ul>
- </div>
- </div>
- </div>
搜索栏JavaScript事件
搜索 | 在"data-search-list"<div class="list-block">中被指定的列表元素 | 在搜索过程中(搜索域改变)事件会被触发。事件包含搜索请求(e.detail.query)和找到的HTML元素(e.detail.foundItems) |
清空搜索 | 在"data-search-list"<div class="list-block">中被指定的列表元素 | 当用户点击搜索栏“清空”按钮(a href="#" class="searchbar-clear")的时候,事件被触发 |
启用搜索 | 在"data-search-list"<div class="list-block">中被指定的列表元素 | 当搜索栏起作用时,事件被触发 |
禁用搜索 | 在"data-search-list"<div class="list-block">中被指定的列表元素 | 当搜索栏被禁用时 - 用户点击“取消”按钮或"searchbar-overlay"元素,事件被触发 |
相关推荐
资源名称:iOS开发视频教程资源目录:【】iOS开发视频教程-第01讲-iOS历史介绍【】iOS开发视频教程-第02讲-XCode安装【】iOS开发视频教程-第03讲-UIView_PPT【】iOS开发视频教程-第04讲-UILabel【】iOS开发视频教程-...
Framework7 是免费开源的 HTML 移动端框架,用来开发混合移动端应用或者 iOS 7 的 Web 应用,并且带有 iOS 7 的原生外观和感觉。Framework7 也是独立的原型应用工具。Framework7 使用 Javascript,CSS 和 HTML 来...
资源名称:《iOS开发零基础入门教程》(40集)资源目录:【】传智播客《iOS开发零基础入门教程》1.1【】传智播客《iOS开发零基础入门教程》1.2【】传智播客《iOS开发零基础入门教程》1.3【】传智播客《iOS开发零基础...
framework7-icons, Framework7的免费iOS图标字体 Framework7图标Framework7的高级和免费ios图标字体。这种字体可以用在 Framework7插件中,但是你可以在任何地方看到它适合它,个人或者商业。 它是免费的使用和许可...
Framework7是一款免费、开源的移动应用框架,旨在为开发者提供构建iOS和Android应用的全套工具。它提供了丰富的组件库,包括导航、表单、视图、滑块等,使开发者能够轻松实现原生应用的界面和交互效果。 二、Vue.js...
之前遇到的需求,ios上没有类似的实现。搞了好久在网上搜了很多资料都不能解决最后找到了一个c/c++的底层源码,才实现了最后整理了下上传了。是个ios的demo很详细你定能看懂的。运行在xcode环境下,关键算法的文件是...
Objective-C是苹果公司开发的一种面向对象的编程语言,广泛应用于MacOS和iOS平台的软件开发。Cocoa是Apple为这两种操作系统提供的原生开发框架,包含了大量用于构建图形用户界面、处理事件、管理文件系统等任务的...
iPhone开发入门到精通视频教程资源目录:【】iOS开发源码系列---工具【】iOS开发源码系列---应用【】iOS开发源码系列---游戏【】iOS开发源码系列---类库与框架【】iOS开发真机测试与发布【】iOS开发视频教程01~05...
### UI第一章:无限互联iOS开发教程课件 -- iPhone开发入门 #### iOS系统概述与架构 - **iOS系统**:作为苹果公司专为iPhone、iPod touch及iPad设计的操作系统,iOS自诞生以来就以其简洁易用的特点受到全球用户的...
提供的【应用】★★★★-iOS framework 制作教程【非静态包】源码示例,应该包含了完整的框架创建过程和相关代码,你可以通过阅读和运行这个项目来加深理解。在实践中,你可以尝试修改源代码,添加新的功能,或者...
Framework7是一款强大的、免费的HTML5移动应用框架,专为构建具有原生iOS和Android界面风格的混合式移动应用而设计。它允许开发者使用Web技术(如HTML, CSS, JavaScript)来创建高度交互且功能丰富的应用程序,同时...
总之,手机移动端电商在iOS和Android平台上的实现涉及多方面的技术和策略。从H5页面的构建到原生功能的集成,再到用户体验的优化,每一个环节都需要精心设计和实施。随着技术的不断发展,未来的移动端电商将更加智能...
Framework7 是免费开源的 HTML 移动端框架,用来开发混合移动端应用或者 iOS 7 的 Web 应用,并且带有 iOS 7 的原生外观和感觉。Framework7 也是独立的原型应用工具。
移动端兼容安卓IOS的高仿支付密码输入功能。 类似支付宝,微信的支付密码功能。
本资源“iOS开发框架”显然是一个专为学习和开发iOS应用而设计的集合,其中包含了多个有用的工具和示例项目。 1. **CTools使用.rtf**: 这个文件可能是关于`CTools`的使用指南,`CTools`通常是指一套用于iOS开发的...
"ios开发-使用mpass移动开发框架在ios端抓包hook脚本.zip"是一个针对iOS开发者的重要资源,它包含了一套利用mpass移动开发框架在iOS设备上实现抓包功能的hook脚本。本文将详细介绍如何使用这个框架和脚本来实现iOS端...
iOS Debug环境 arm64与x86_64架构 WebRTC.framework Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64] Mach-O 64-bit dynamically linked ...
Appium 是一个流行的开源自动化测试框架,用于移动应用测试,支持iOS和Android平台。在iOS自动化测试领域,Appium 提供了对真实设备和模拟器的控制能力,使得开发者和测试工程师可以编写跨平台的自动化测试脚本。...
road-ios-framework, 道路- 快速 Objective C 应用程序开发 一组重用组件利用额外的维度属性定向程序 。##Components基础类的属性。反射和辅助扩展支持核心 。服务 implementation服务定位器 Pattern的实现,集中...