本來想用bootstrap-star-rating的,就是上傳插件那個組做的。但是還是css的問題
后來百度了個別的東西,第一頁就能搜到,就不妨鏈接了。
* @version 2.5.2
* @since 2010.06.11
* @author Washington Botelho
* @documentation wbotelhos.com/raty
很老的一個東西,能用就好。
<div id="star{{ite.$id}}" ng-bind="getrating(this,ite)"></div>
<script src="@Url.Content("~/Content/Component/star-rating/jquery.raty.js")"></script>
這個ite是循環的數據而已,星星插件只要里面一個分數就行
一般來講評分是1~5,半星是0.5,不過我們要求0~10,半星是1
於是:
$scope.getrating = function (o, obj) { $("#star" + obj.$id).raty({ path: '@Url.Content("~/Content/Component/star-rating/img/")',//這是星星圖= =其中有選中/沒選/半選 3張 click: function (score, evt) { obj.Score = score * 2;//這里×2了 }, half: true,//這是開啟半分的 readOnly: $scope.sstate != 1, score: obj.Score / 2,//這里要除2- - size: 24, hints: [2, 4, 6, 8, 10]//這里也要改 }); }
然后要,我這邊還有要求,鼠標放上去要顯示123456789分= =
這個要改下源文件jquery.raty.js了。
在_roundStars 這個方法中加了一行
this.stars.eq(Math.ceil(score) - 1).attr('title', score * 2);
不然這個title(也就是鼠標放上去顯示的文字)會按照初始化(hints: [2, 4, 6, 8, 10])只顯示出246810
整段是這樣的,但是有個問題 10分和0分好像不顯示,不過無所謂了= =
--------------------------------------------------------- }, _roundStars: function (score) { var rest = (score - Math.floor(score)).toFixed(2); if (rest > this.opt.round.down) { var icon = 'starOn'; // Up: [x.76 .. x.99] if (this.opt.halfShow && rest < this.opt.round.up) { // Half: [x.26 .. x.75] icon = 'starHalf'; } else if (rest < this.opt.round.full) { // Down: [x.00 .. x.5] icon = 'starOff'; } this.stars.eq(Math.ceil(score) - 1).attr('src', this.opt.path + this.opt[icon]); } // Full down: [x.00 .. x.25] this.stars.eq(Math.ceil(score) - 1).attr('title', score * 2); }, _target: function (score, evt) { ---------------------------------------------------------