2015-11-03 84 views
0

我是新來的意思是堆棧和第一次在AngularJS中編寫代碼,我試圖在下面的index.html文件中實現排序,分頁和過濾。什麼是不正確怎麼想實現,請大家幫忙 這裏是我的index.html文件 -AngularJS中的排序,過濾和分頁

<!DOCTYPE> 
 
<html ng-app="myApp"> 
 

 
<head> 
 
    <!-- Latest compiled and minified CSS --> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> 
 

 
    <!-- Optional theme --> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css"> 
 

 
    <title>eAPI Test Execution Portal</title> 
 
</head> 
 

 
<body> 
 
    <div class="container" ng-controller="AppCtrl"> 
 
    <h1>eAPI Test Execution Portal</h1> 
 

 
    <table class="table table-fluid"> 
 
     <thead> 
 
     <tr> 
 
      <th><a href="" ng-click="orderByField='runId'; reverseSort = !reverseSort">runId</a> 
 
      <th><a href="" ng-click="orderByField='apiName'; reverseSort = !reverseSort">apiName</a> 
 
      </th> 
 
      </th> 
 
      <th><a href="" ng-click="orderByField='runTime'; reverseSort = !reverseSort">runTime</a> 
 
      </th> 
 
      <th><a href="" ng-click="orderByField='Report'; reverseSort = !reverseSort">Report</a> 
 
      </th> 
 
      <th><a href="" ng-click="orderByField='numOfTestExecuted'; reverseSort = !reverseSort">numOfTestExecuted</a> 
 
      </th> 
 
      <th><a href="" ng-click="orderByField='numOfTestFailed'; reverseSort = !reverseSort">numOfTestFailed</a> 
 
      </th> 
 
      <th><a href="" ng-click="orderByField='status'; reverseSort = !reverseSort">status</a> 
 
      </th> 
 
     </tr> 
 
     </thead> 
 
     <tbody> 
 
     <tr> 
 
      <td> 
 
      <input type="text" ng-model="search.runId" placeholder="Search by runId" /> 
 
      </td> 
 
      <td> 
 
      <input type="text" ng-model="search.apiName" placeholder="Search by apiName" /> 
 
      </td> 
 
      <td> 
 
      <input type="text" ng-model="search.runTime" placeholder="Search by runTime" /> 
 
      </td> 
 
      <td> 
 
      <input type="url" ng-model="search.Report" placeholder="Search by Report URL" /> 
 
      </td> 
 
      <td> 
 
      <input type="text" ng-model="search.numOfTestExecuted" placeholder="Search by numOfTestExecuted" /> 
 
      </td> 
 
      <td> 
 
      <input type="text" ng-model="search.numOfTestFailed" placeholder="Search by numOfTestFailed" /> 
 
      </td> 
 
      <td> 
 
      <input type="text" ng-model="search.status" placeholder="Search by status" /> 
 
      </td> 
 

 
     </tr> 
 
     <tr ng-repeat="contact in contactlist"> 
 
      <td>{{contact.runId}}</td> 
 
      <td>{{contact.apiName}}</td> 
 
      <td>{{contact.runTime}}</td> 
 
      <td>{{contact.Report}}</td> 
 
      <td>{{contact.numOfTestExecuted}}</td> 
 
      <td>{{contact.numOfTestFailed}}</td> 
 
      <td>{{contact.status}}</td> 
 
     </tr> 
 
     <tr ng-repeat="contact in contactlist | orderBy:predicate:reverse | filter:paginate| filter:search" ng-class-odd="'odd'"> 
 
      <td>{{user.runId}}</td> 
 
      <td>{{user.apiName}}</td> 
 
     </tr> 
 
     </tbody> 
 
    </table> 
 
    <pagination total-items="totalItems" ng-model="currentPage" max-size="5" boundary-links="true" items-per-page="numPerPage" class="pagination-sm"> 
 
    </pagination> 
 
    </div> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js"></script> 
 
    <script src="controllers/controller.js"></script> 
 
</body> 
 

 
</html>

這裏是controller.js文件 - (如果你想嘗試在當地,使用平均堆棧)

var myApp = angular.module('myApp', []); 
 
myApp.controller('AppCtrl', ['$scope', '$http', 
 
    function($scope, $http) { 
 
    console.log("Hello World from controller"); 
 

 

 
    var refresh = function() { 
 
     $http.get('/contactlist').success(function(response) { 
 
     console.log("I got the data I requested"); 
 
     $scope.contactlist = response; 
 
     $scope.contact = ""; 
 
     }); 
 
    }; 
 

 
    refresh(); 
 

 
    $scope.addContact = function() { 
 
     console.log($scope.contact); 
 
     $http.post('/contactlist', $scope.contact).success(function(response) { 
 
     console.log(response); 
 
     refresh(); 
 
     }); 
 
    }; 
 

 
    $scope.remove = function(id) { 
 
     console.log(id); 
 
     $http.delete('/contactlist/' + id).success(function(response) { 
 
     refresh(); 
 
     }); 
 
    }; 
 

 
    $scope.edit = function(id) { 
 
     console.log(id); 
 
     $http.get('/contactlist/' + id).success(function(response) { 
 
     $scope.contact = response; 
 
     }); 
 
    }; 
 

 
    $scope.update = function() { 
 
     console.log($scope.contact._id); 
 
     $http.put('/contactlist/' + $scope.contact._id, $scope.contact).success(function(response) { 
 
     refresh(); 
 
     }) 
 
    }; 
 

 
    $scope.deselect = function() { 
 
     $scope.contact = ""; 
 
    } 
 

 
    } 
 
]);

你可以使用這個在您的本地蒙戈插入數據 -

db.contactlist.insert({"runId" : "1212","apiName" :  "transactions","runTime" : "DateAndTime","Report" : "URL","numOfTestExecuted" : "3","numOfTestFailed" : "3","status" : "Passed"}) 
+0

提示:您正在使用分頁指令,您還應該爲您的分類創建指令。 – squadwuschel

+0

@squadwuschel - 感謝您的提示,將不勝感激,如果你可以更新代碼。正如我所提到的,我是Angular的新手,在實際編碼的過程中學習。希望我有時間參加課程或課程 – inCode

回答

0

這將是冷靜,如果你能告訴我什麼是不是在你的榜樣工作,也許會有更好的你的問題有點鑽到三個問題:

排序,尋呼和過濾。

爲其中的每一個創建一個示例並嘗試實現它,然後詢問直接問題什麼不起作用。

- >因爲每個問題都可以獨立解決,然後更容易理解漏洞是如何協同工作的。

你可以爲你的每個問題創建一個獨立的指令。

+0

感謝您的指導 - 問題1 - 我在文本框中鍵入一些東西,它會在我輸入時找到所有匹配的runId。問題2 - 通過這個'runId',我希望能夠點擊後發生。 – inCode

+0

你的第一個問題是,你在桌上有兩個重複 - 我不明白爲什麼。但是,首先創建一個新的測試項目,您可以測試每個功能,直到它按照您的要求工作,當您遇到問題時,然後爲每個問題創建一個新的StackOverflow帖子。 – squadwuschel