2016-04-19 62 views
2

我能夠從數據庫中獲取的一個號碼,以html爲引導星級評級的角度JS

<tr ng-repeat="review in reviews "> 
      <td>{{review.reviewer}}</td> 
      <td>{{review.comment}}</td> 
      <td>{{review.rating}}</td> 

在這裏顯示出來,{{review.rating}}在規定數量。

如何使用Bootstrap顯示給定數字的星級?

回答

6

您可以使用Angularjs引導UI指令:

https://angular-ui.github.io/bootstrap/

- >評級(ui.bootstrap.rating)

例如:http://plnkr.co/edit/wpfxg0zqSLHPtQVBHdGi?p=preview

的index.html

<div ng-controller="RatingDemoCtrl"> 
    <h4>Rating</h4> 
    <uib-rating ng-model="rate" max="max" read-only="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating> 
     <span class="label" ng-class="{'label-warning': percent<30, 'label-info': percent>=30 && percent<70, 'label-success': percent>=70}" ng-show="overStar && !isReadonly">{{percent}}%</span> 
</div> 

app.js

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']); 
angular.module('ui.bootstrap.demo').controller('RatingDemoCtrl', function ($scope) { 
    $scope.rate = 7; 
    $scope.max = 10; 
    $scope.isReadonly = false; 

    $scope.hoveringOver = function(value) { 
    $scope.overStar = value; 
    $scope.percent = 100 * (value/$scope.max); 
    }; 

}); 
+1

非常感謝。它有助於 –

+1

偉大,你可以將它設置爲答案,如果案件 – thegio