2016-07-04 74 views
-1

,这里是我的html table.i使用已经绑定表角JS采用了棱角分明的js

<body ng-app> 
    <div class="wrapper wrapper-content" ng-controller="InboxMailCtrl"> 
     <div class="input-group-btn"> 
      <button type="submit" ng-model="search" class="btn btn-sm btn-primary"> 
       Search 
      </button> 
     </div> 
     <table class="table table-hover table-mail"> 
      <tbody> 
       <tr ng-repeat="CU in InboxList"> 
        <td class="mail-ontact"><a href="" ng-click="ViewEmailDetails(CU.InboxMailID)">{{CU.Reciever}}</a></td> 
        <td class="mail-subject"><a href="" ng-click="ViewEmailDetails(CU.InboxMailID)">{{CU.Subject}}</a></td> 
       </tr> 
      </tbody> 

     </table> 
    </div> 

在这里HTML表格搜索我的angularjs code.i要添加搜索功能

var InboxDraftMailCtrl = function ($scope, $http) { 
    BindDraftMailList(); 

function BindDraftMailList(Data) { 
    debugger 
    var UserEmail = sessionStorage.getItem("loginUserID"); 
    var obj = { 
     data: UserEmail 
    } 
    debugger 
    $http({ 
     url: "MailRoute/getDataForDraftMail", 
     dataType: 'json', 
     method: 'POST', 
     data: obj, 
     headers: { 
      "Content-Type": "application/json" 
     } 
    }).success(function (response) { 

    }) 
      .error(function (error) { 
       alert(error); 
      }); 
} 

什么,我已经加入到实现搜索功能

+1

明显没有尝试简单的网络搜索简单的术语,如'角搜索'或将找到** [过滤器文档](https://docs.angularjs.org/api/ng/filter/filter )**和许多其他结果 – charlietfl

回答

0

你可以使用angularJS的过滤方法。 Filter方法从数组中选择一个项目的子集并将其作为新数组返回。 将html代码编写为。

<body ng-app> 
    <div class="wrapper wrapper-content" ng-controller="InboxMailCtrl"> 
    <div class="input-group-btn"> 
     <button type="submit" ng-model="search" class="btn btn-sm btn-primary"> 
      Search 
     </button> 
    </div> 
    <table class="table table-hover table-mail"> 
     <tbody> 
      <tr ng-repeat="CU in InboxList| filter:search"> 
       <td class="mail-ontact"><a href="" ng-click="ViewEmailDetails(CU.InboxMailID)">{{CU.Reciever}}</a></td> 
       <td class="mail-subject"><a href="" ng-click="ViewEmailDetails(CU.InboxMailID)">{{CU.Subject}}</a></td> 
      </tr> 
     </tbody> 

    </table> 

此链接将有助于解决您的问题。 link

+0

不提供解释为什么你会这样做 – charlietfl

+0

好的。我会提供它。其实我正在更新我的答案。 –

+0

那么,至少我所理解的问题是,他想使用搜索按钮来创建一个http.post请购单服务器端并获取与搜索词匹配的电子邮件。如果是这样,你的回答是不正确的。另一方面,他没有很好地解释他想要什么。 – developer033

0

除非你正在寻找过滤取出已经结果,假设搜索方法/ MailRoute/getDataForDraftMail,你希望做这样的事情:

var InboxDraftMailCtrl = function ($scope, $http) { 

     $scope.Search = function(){ 
     $http({ 
     url: "MailRoute/getDataForDraftMail", 
     dataType: 'json', 
     method: 'POST', 
     data: obj, 
     headers: { 
     "Content-Type": "application/json" 
    }}).success(function (response) { 

     // Fetch what you want from response 
     $scope.InboxList = response.data.emails; // Something like this 
    })//. etc 
} 

而在HTML按钮单击应该是:

<button type="submit" ng-click="Search();" class="btn btn-sm btn-primary"> 
     Search 
</button>