【问题标题】:Implementing a Search Bar Under a Tab in Ionic在 Ionic 的选项卡下实现搜索栏
【发布时间】:2016-06-08 03:27:52
【问题描述】:

我在项目的“搜索”标签下添加搜索栏时遇到问题。我使用与 this 布局方式类似的逻辑,但它在 ionic serve --lab 实时浏览器预览中无法正常工作。搜索栏最终不够宽,位于要过滤的列表的中间。

当我将搜索栏的代码直接放在 html 文件中的 <ion-view> 标记之外时,它不会显示出来。当我将它直接放在<ion-content> 标签内时,它看起来是错误的。关于我如何实现这一点的任何提示?

这是我正在使用的搜索栏的代码:

<ion-header-bar class="bar-light bar-subheader">
    <input type="search" placeholder="Filter contacts..." ng-model="search" ng-focus="searchFocused = true" ng-blur="searchFocused = false" ng-change="scrollTop()" class="full-width">
    <button ng-if="search.length" class="button button-icon ion-android-close input-button" ng-click="clearSearch()">
      </button>
  </ion-header-bar>

【问题讨论】:

标签: html angularjs cordova ionic-framework


【解决方案1】:

如果您将bar 类与sub-header 放在一起,您的搜索栏问题应该会解决。 在这里结帐 -

angular.module('myApp', ['ionic'])
.controller('MainCtrl', function($scope) {
  $scope.clearSearch = function() {
    $scope.search = '';
  };
});
.button.button-icon.input-button {
  position: absolute;
  right: 0;
  top: 5px;
  color: #bbb;
}

.item img {
  height: 60px;
  width: 60px;
  float: left;
  margin-top: 20px;
  margin-right: 10px;
}

.my-item.item {
  padding-top: 0;
  padding-bottom: 0;
}

.full-width {
  width: 100%;
}
<script src="http://code.ionicframework.com/1.1.0/js/ionic.bundle.js"></script>
<link href="http://code.ionicframework.com/1.1.0/css/ionic.css" rel="stylesheet"/>

<body ng-app="myApp" ng-controller="MainCtrl">
  <ion-header-bar class="bar-positive">
    <h1 class="title">Header</h1>
  </ion-header-bar>
  <ion-header-bar class="bar bar-subheader">
    <input type="search"
           placeholder="Filter contacts..."
           ng-model="search"
           ng-focus="searchFocused = true"
           ng-blur="searchFocused = false"
           ng-change="scrollTop()"
           class="full-width">
    <button ng-if="search.length"
            class="button button-icon ion-android-close input-button"
            ng-click="clearSearch()">
    </button>
  </ion-header-bar>
  <ion-content>
    <ion-list>
      <ion-item class="my-item">item 1</ion-item>
      <ion-item class="my-item">item 2</ion-item>
      <ion-item class="my-item">item 3</ion-item>
      <ion-item class="my-item">item 4</ion-item>
    </ion-list>
  </ion-content>
</body>

【讨论】:

  • 嗯...搜索栏显示(仅适用于iPhone版本),但是1)内容消失了2)“X”按钮仍在屏幕中间
猜你喜欢
  • 2017-08-27
  • 1970-01-01
  • 2017-11-14
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多