【发布时间】:2016-02-26 12:43:52
【问题描述】:
在用户可以对项目进行投票的项目上工作,并且在 orderBy 之后,该功能仅适用于项目的原始索引。我想通过从数据库中提取但有问题的 ID 属性来跟踪项目。我也尝试过传递对象而不是它们的索引,但我再次无法理解它。
相关JS
angular.module("cardSite", ['masonry'])
.controller('mainCtrl', function($scope, dataService) {
$scope.cards = [];
dataService.getCards().then(function(response) {
$scope.cards = response.data;
}, function() {});
$scope.plusOne = function($index) {
$scope.cards[$index].card_rating += 1;
};
});
相关 HTML
<div class="col-lg-3 tile grid-item" ng-repeat="card in cards | orderBy : '-card_rating' | limitTo:8 track by card.ID">
<div class="panel panel-default {{ card.card_category | lowercase }}_panel">
<p>Card ID: {{card.ID}}</p>
<!DOCTYPE svg>
<p ng-click="plusOne($index)"> Vote up</p>
<p>{{card.card_rating}}</p>
</div>
有人有什么建议吗?
【问题讨论】:
标签: javascript angularjs