好吧,这很简单:当完成工作的百分比低于10%时,我需要隐藏一个<li>
。
这是我的twig文件中的元素,我想隐藏第一个li选项卡,并在第一个隐藏时使第二个激活:
<nav ng-controller="OverviewController">
<ul class="nav nav-tabs" role="tablist">
<li class="active"></li>
<li></li>
<li></li>
<li ng-if="announcements.length > 0">
</li>
</ul>
</nav>
还有一个名为&#34; percentage
&#34;的变量。在我的ProjectManager.php
中,如果低于或高于10%,将成为隐藏或显示的触发器。
基本上,想要这样的事情:if(percentage < 10%) { ng-hide }
编辑: OverviewController
define([], function() {
OverviewController.$inject = ['$scope', '$timeout', 'AnnouncementFactory', 'CommentFactory'];
/**
* Overview controller.
*/
function OverviewController($scope, $timeout, AnnouncementFactory, CommentFactory) {
$scope.announcementNotification = AnnouncementFactory.hasUnreadAnnouncements();
$scope.announcements = AnnouncementFactory.getAnnouncements();
$scope.commentNotification = CommentFactory.hasUnreadComments();
// Cached this page date.
var date = new Date().toISOString();
/**
* Set all announcements as read.
*/
$scope.setAllAnnouncementsAsRead = function() {
if (!$scope.announcementNotification) {
return;
}
AnnouncementFactory.setAllAnnouncementsAsRead(date).then(function() {
$scope.announcementNotification = false;
});
};
/**
* Set all comments as read.
*/
$scope.setAllCommentsAsRead = function() {
if (!$scope.commentNotification) {
return;
}
CommentFactory.setAllCommentsAsRead().then(function() {
$scope.commentNotification = false;
});
};
}
return OverviewController;
});
ProjectManager.php
/**
* Update percentage.
*/
public function updatePercentage($project)
{
$done = 0;
$total = 0;
list($pages, $status) = $this->participationManager->getPagesInPath($project);
foreach ($pages as $pageData) {
$widgetsDoneIds = array_keys($status[$pageData['module']]['pages'][$pageData['page']->getId()]['widgetsDone']);
foreach ($pageData['widgets'] as $widget) {
if (in_array($widget->getId(), $widgetsDoneIds)) {
$done++;
}
}
$total += count($pageData['widgets']);
}
$percentage = $total !== 0 ? ($done / $total) * 100 : 0;
$project->setPercentage($percentage);
$this->entityManager->persist($project);
$this->entityManager->flush($project);
}