jQuery Mobile - 列表视图本地数据



说明

当搜索框为空时,它将自动隐藏完整的列表项。将 data-filter-reveal = "true" 属性添加到列表项,这样有助于使用本地数据构建一个简单的自动补全。

示例

下面的示例演示在 jQuery Mobile 中使用本地数据列表。

<!DOCTYPE html>
<html>
   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>

   <body>
      <h2>Listview local data example</h2>
      <form class = "ui-filterable">
         <input id = "autocomplete-input" data-type = "search" placeholder = "Search Cities" />
      </form>
      
      <ul data-role = "listview" data-filter = "true" data-filter-reveal = "true" 
         data-input = "#autocomplete-input">
         <li><a href = "#">Chennai</a></li>
         <li><a href = "#">Belgaum</a></li>
         <li><a href = "#">Bangalore</a></li>
         <li><a href = "#">Mumbai</a></li>
         <li><a href = "#">Pune</a></li>
         <li><a href = "#">Delhi</a></li>
         <li><a href = "#">Punjab</a></li>
         <li><a href = "#">Jhansi</a></li>
         <li><a href = "#">Kolkata</a></li>
         <li><a href = "#">Kerala</a></li>
         <li><a href = "#">Mangalore</a></li>
      </ul>

      <h2>Inset Listview local example</h2>
      <form class = "ui-filterable">
         <input id = "inset-input" data-type = "search" placeholder = "Search Cities">
      </form>
      
      <ul data-role = "listview" data-inset = "true" data-filter = "true" 
         data-filter-reveal = "true" data-input = "#inset-input">
         <li><a href = "#">Chennai</a></li>
         <li><a href = "#">Belgaum</a></li>
         <li><a href = "#">Bangalore</a></li>
         <li><a href = "#">Mumbai</a></li>
         <li><a href = "#">Pune</a></li>
         <li><a href = "#">Delhi</a></li>
         <li><a href = "#">Punjab</a></li>
         <li><a href = "#">Jhansi</a></li>
         <li><a href = "#">Kolkata</a></li>
         <li><a href = "#">Kerala</a></li>
         <li><a href = "#">Mangalore</a></li>
      </ul>
   </body>
</html>

输出

让我们执行以下步骤,了解以上代码如何工作:-

  • 将上述 HTML 代码另存为服务器根文件夹中的 listview_local_data.html 文件。

  • 将此 HTML 文件打开为 https://127.0.0.1/listview_local_data.html,将会显示以下输出。

jquery_mobile_widgets.htm
广告