【问题标题】:is there any way to search on while loop populated data with angularjs有没有办法用 angularjs 搜索 while 循环填充的数据
【发布时间】:2017-05-03 17:50:30
【问题描述】:

我有一个情况,我以前的代码是 2000 到 3000 行,所以我不希望 angular $httppopulate 我页面上的所有数据。而是我想要php populated 数据上的search 功能。

问题:如何在php populated data 中包含angular 搜索功能?

我的搜索按钮:

<input type="search" ng-model="searchText" ng-change="search()"/>

我的控制器:

myApp.controller('clickListenerCtrl',function($scope,$http){

  $scope.search = function(){

      console.log($scope.searchText);  // im able get typed text
  }
});

我的 while 循环:

<table ng-controller="clickListenerCtrl">
<thead>
  <tr>
    <th>Id</th>
    <th>Name</th>
  </tr>
</thead>
<tbody>
  <?php while($row = ......){ ?>
 <tr>
    <td><?php echo $row['id'] ?></td>
    <td><?php echo $row['name'] ?></td>
 </tr>
 <?php } ?>
</table>

在核心 angularjs 中我们可以这样做(解决方案):

<table ng-controller="clickListenerCtrl">
<thead>
  <tr>
    <th>Id</th>
    <th>Name</th>
  </tr>
</thead>
<tbody>
 <tr ng-repeat="x in data | filter:searchText">
    <td>{{x.id}}</td>
    <td>{{x.name}}</td>
 </tr>
</table>

请帮助我提前谢谢!!!!!!!!!!!!!!!!!!!!!!!!

【问题讨论】:

  • 你想用angular还是php搜索?
  • 搜索角度
  • for populated 前端
  • 为什么不使用 http 服务从 angularjs 获取相同的数据。这样您就可以控制数据

标签: javascript php jquery angularjs html


【解决方案1】:

你的控制器可能是这样的-

            myApp.controller('clickListenerCtrl',function($scope,$http){

            $scope.search = function(){
            console.log($scope.searchText);  // im able get typed text                      

            //use ajax to call php to fetch serach results and then 
            // display the same in view
            // then you will not need filter in ng-repeat

            $http({
               url: "search.php",
               method: 'POST',
               headers: {'Content-Type': 'application/x-www-form-urlencoded'},
               data: 'searchText='+$scope.searchText
           }).success(function(data, status, headers, config) {

               console.log(data);
               $scope.data = data;


           }).error(function(data, status, headers, config) {
               $scope.status = status;
               console.log("error");
           });  

          };
        });

【讨论】:

    猜你喜欢
    • 2011-04-03
    • 2012-09-15
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    相关资源
    最近更新 更多