Currently at the moment I am able display text from a loop and above the text a red circle displays using the i class and code below:
<div id="testwrap">
#foreach (mainnav mainnav in #Model)
{
if (mainnav.HasSideNav == 0)
{
<a style="color:red" href='#Url.Action("Content", new { id = mainnav.contentID })' class="ajax2">#mainnav.DisplayLabel</a>
}
else
{
<div class="col-sm-3 text-center feature">
<i class="fa fa-tablet iconred"></i>
<a style="color:blue" href='#Url.Action("SideNavLevel1", new { id = mainnav.MNavSubID })' class="ajax2">#mainnav.DisplayLabel</a>
</div>
}
}
</div>
My aim is it to have the icon be blue, green, yellow, orange etc...
I have tried to add in a counter but it doesn't work.
Can anybody help me to add the loop/ counter in to change where is says iconred to iconblue etc...?
You can keep your colors in an array and use that along with a counter.
#{
var counter = 0;
string[] colors = new string[] { "red", "blue", "orange","green" };
}
<div id="testwrap">
#foreach (var mainnav in YourCollection)
{
if (mainnav.HasSideNav == 0)
{
<a style="color: red" href='#' class="ajax2">#mainnav.DisplayLabel</a>
}
else
{
<div class="col-sm-3 text-center feature">
<i class="fa fa-tablet icon#(colors[counter])"></i>
<a style="color: blue" href='#' class="ajax2">#mainnav.DisplayLabel</a>
</div>
}
counter++;
if (counter == 4)
{
counter = 0;
}
}
</div>
If you have more than 4 items in your collection, the fifth item will be again red and so on.
Related
I am trying to remove item using ng-if and ng-else-if.
"ng-if="navItem.gbn.indexOf('12345') !== -1" is true then array item only show contains('12345') items.
but the item still remain in array so I think ng-else-if is not working.
I don't know how to delete it.
I have the following Angular code:
<div ng-controller="PIDAEController">
<div class="container-fluid" style="padding-top:30px;">
<div class="row">
<div class="col-lg-2 col-md-3 col-xs-6 tubmbimg" ng-repeat="navItem in navItems | Fpage: curPage * pageSize | limitTo:pageSize" ng-if="navItem.gbn.indexOf('12345') !== -1">
<a class="thumbnail border" href="#/item/{{navItem.site}}">
<div class="b-marjin">
<span align="center" class="label label-primary full-width" >{{ navItem.gbn }}</span>
</div>
<div>
<img style="border: 1px solid black;" class="img-responsive full-width" src="{{navItem.pimg}}" alt="">
</div>
<div align="center" class="under-block">
<span title="{{ navItem.pname }}" align="center">{{ navItem.pname2}}</span>
</div>
</a>
</div>
<div ng-else-if="navItems.splice(navItem, 1)"></div>
</div>
</div>
</div>
angular.forEach(item, function (value, key) {
var keepGoing = true;
if(keepGoing) {
if(value.gbn.indexOf("11600") != -1) {
$scope.initialized = true;
$scope.navItems = item;
$scope.curPage=0;
$scope.pageSize=20;
$scope.numberOfPage = Math.ceil(item.length / $scope.pageSize);
keepGoing = false;
}
else {
$scope.navItems.splice(key, 1);
}
}
});
ng-else-if does NOT EXIST. its neither angular or angularJS.
In the line
<div ng-else-if="navItems.splice(navItem, 1)"></div>
splice requires navItem to be an index/int, not an object.
As an alternative to ng-else-if you can simply do:
ng-if="navItem.gbn.indexOf('12345') == -1
Also, splice would return the removed array item when found, not sure if "ng-if" handles that as being TRUE.
I have the JQuery code below. I changed the text between a button element from + to x in second if statement. Now, when the button is displaying x, I wanted to change the text to + in first if statement using $(this).text("+");, yet the button is displaying x even after the change. I have checked if the text was changed to + using console.log() and it says it has changed to +. But, why isn't the result showing its effect on the button?
let players = [];
let remainingPlayers = 11;
$(".card > button").click(function(e) {
let removePlayer = "";
let index = -1;
if ($(this).text() !== "+") {
removePlayer = $(this).attr("value");
index = players.indexOf(removePlayer);
if (index != -1) {
$(this).text("+");
players.splice(index, 1);
console.log(players);
console.log($(this).text());
}
}
if (remainingPlayers != 0) {
remainingPlayers -= 1;
players.push($(this).attr("value"));
$(this).text("x");
$(this).addClass("btn btn-danger button-select-players");
$("#pl-remain").text(remainingPlayers);
} else {
alert("You can't select more players");
console.log(players);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-lg-6 col-md-12 col-sm-12">
<div class="card" style="width: 15rem;">
<img src="..." class="card-img-top" alt="...">
<button class="btn btn-success button-select-players" type="button" name="button" value="xyz">+</button>
<ul class="list-group list-group-flush">
<li class="first-li list-group-item">Name</li>
<li class="list-group-item">0</li>
</ul>
</div>
</div>
I have a small accordion on one of my site's pages and I cannot seem to toggle properly between the plus and the minus signs.
it toggles fine if I open and close the same accordion item but the problem is when I click on another item while this one is active, it leaves the minus sign on.
<div class="accordion">
<div class="accordion-item item1 verde">
<div class="title"><i class="plusminus fas fa-plus" aria-hidden="true"></i>item1</div>
<div class="content"><p>content for item 1</p></div>
</div>
<div class="accordion-item item2 verde">
<div class="title"><i class="plusminus fas fa-plus" aria-hidden="true"></i>item2</div>
<div class="content"><p>content for item 2</p></div>
</div>
</div>
$('.accordion-item .heading').on('click', function(e) {
e.preventDefault();
// Add the correct active class
if($(this).closest('.accordion-item').hasClass('active')) {
// Remove active classes
$('.accordion-item').removeClass('active');
} else {
// Remove active classes
$('.accordion-item').removeClass('active');
// Add the active class
$(this).closest('.accordion-item').addClass('active');
}
if($(this).closest('.accordion-item').hasClass('active')) {
$(this).find(".plusminus").removeClass('fa-plus').addClass('fa-minus');
} else {
$(this).find(".plusminus").removeClass('fa-minus').addClass('fa-plus');
}
// Show the content
var $content = $(this).next();
$content.slideToggle(100);
$('.accordion-item .content').not($content).slideUp('fast');
});
You only need to reset the fa-minus and fa-plus classes at the begining of the event.
Change every plusminus class to fa-plus and at the end of the event handler you set as you are already doing.
$('.accordion-item .heading').on('click', function (e) {
e.preventDefault();
$(".plusminus").removeClass('fa-minus').addClass('fa-plus');
// Add the correct active class
if ($(this).closest('.accordion-item').hasClass('active')) {
// Remove active classes
$('.accordion-item').removeClass('active');
} else {
// Remove active classes
$('.accordion-item').removeClass('active');
// Add the active class
$(this).closest('.accordion-item').addClass('active');
}
if ($(this).closest('.accordion-item').hasClass('active')) {
$(this).find(".plusminus").removeClass('fa-plus').addClass('fa-minus');
} else {
$(this).find(".plusminus").removeClass('fa-minus').addClass('fa-plus');
}
// Show the content
var $content = $(this).next();
$content.slideToggle(100);
$('.accordion-item .content').not($content).slideUp('fast');
});
<div class="accordion">
<div class="accordion-item item1 verde">
<a href="#" class="heading">
<div class="title"><i class="plusminus fas fa-plus" aria-hidden="true"></i>item1</div>
</a>
<div class="content">
<p>content for item 1</p>
</div>
</div>
<div class="accordion-item item2 verde">
<a href="#" class="heading">
<div class="title"><i class="plusminus fas fa-plus" aria-hidden="true"></i>item2</div>
</a>
<div class="content">
<p>content for item 2</p>
</div>
</div>
</div>
I'm trying to create rows dynamically with razor but I can't figure out how to wrap this around. What I want is for every 5:e object in my model I want to create a new row/div <div class="row pics_in_a_row"> so that each row contains five or less images.
<section class="slice">
<div class="wp-section">
<div class="container">
<div class="row pics_in_a_row">
#{
int i = 0;
foreach (dbphoto.Models.Image s in Model.images.OrderByDescending(x => x.idimage))
{
if (i % 5 == 0 && i != 0)
{
<br />
}
i++;
if (1 == 1)
{
<div class="flxbox" style="flex: calc(1024/713)">
<a href="#s.HighResolution" data-fancybox="gallery" data-caption="xyz, Stockholm">
<img src="#s.LowResolution" class="img-fluid rounded flximg" />
</a>
</div>
}
}
}
</div>
</div>
</div>
</section>
Bonus question: how can I get the height and width of the image and add it to the calc() css?
You should add the div with class row pics_in_a_row inside your loop
This should create a a row for every 5 items (or less for the last row when the remaining items are less than 5).
<div class="container">
#{
var numberOfColsNeeded = 5;
var totalCounter = Model.images.Count();
var itemCounter = 1;
}
#foreach (var item in Model.images)
{
if (itemCounter % numberOfColsNeeded == 1)
{
#:<div class="row pics_in_a_row">
}
<div class="flxbox" style="flex: calc(1024 / 713)">
<img src="#item.LowResolution" class="img-fluid rounded flximg" />
</div>
if ((itemCounter % numberOfColsNeeded == 0) || ((itemCounter) == totalCounter))
{
#:</div>
}
itemCounter++;
}
</div>
I have a JSON file which has this structure:
{ "short_title":"HB_START_SHORT_TITLE",
"tips{"1":"HB_START_TIPS_1_1","2":"HB_START_TIPS_1_2","3":"HB_START_TIPS_1_3","4":"HB_START_TIPS_1_4"},
},
I would like to print the nested item "tips" as a slider with previous-next buttons.
Therefore I wrote this code in my HTML below:
<ul class="sb-parentlist">
<div data-ng-repeat="parts in data track by $index">
<li>
<div class="sb-open" ng-show="showDetails">
{{parts.short_text|translate}}
<br>
<li><span class="sb-text-title" href="#" ng-click="OpenTips = ! OpenTips"><b>Tips</b></span>
<span ng-show="OpenTips" class="sb-open">
<br>
<div ng-repeat="data in parts.tips track by $index" ng-class="{'tips-hide': $index > $index + 1}">
{{data|translate}}
<br>
<div class="keys">
<button type="button" class="btn btn-pre" ng-click="$index = $index > 1 ? $index - 1 : 1">Previous</button>
<button type="button" class="btn btn-next" ng-click="$index = $index < data.length ? $index + 1 : data.length">Next</button>
</div>
</div>
</span>
</li>
</ul>
</div>
</li>
</div>
</ul>
and the tips-hide class in CSS:
.tips-hide {
left: -100px !important;
opacity: 0 !important;
}
.sb-open {
display: block;
height: auto;
opacity: 1;
transition:all 0.6s ease;
li {
display: block;
}
}
But what I am getting is every element in the list one after the other, with the buttons on the bottom of each one of them.
ScreenShot below:
ng-repeat on object can't be tracked by index (at least not in that way)
I've changed few parts on code to simulate on code snippet, see if it helps.
var app = angular.module('app', []);
app.controller('DemoCtrl', function($scope) {
this.openTips = true;
$scope.tipsIndex = 1;
this.info = [{ "short_title":"HB_START_SHORT_TITLE",
"tips" : {"1":"HB_START_TIPS_1_1","2":"HB_START_TIPS_1_2","3":"HB_START_TIPS_1_3","4":"HB_START_TIPS_1_4"}
}];
$scope.decrement = function() {
if($scope.tipsIndex > 1){
$scope.tipsIndex = $scope.tipsIndex - 1;
}
};
$scope.increment = function(partsIndex) {
if($scope.tipsIndex < partsIndex){
$scope.tipsIndex = $scope.tipsIndex + 1;
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="app">
<div ng-controller="DemoCtrl as demo">
<ul class="sb-parentlist">
<ul class="sb-parentlist">
<div data-ng-repeat="parts in demo.info track by $index">
<li>
<div class="sb-open">
{{parts.short_title}}
<br>
<li><span href="#" ng-click="demo.openTips = !demo.openTips"><b>Tips</b></span>
<span ng-show="demo.openTips" class="sb-open">
<br>
<div ng-repeat="(key, value) in parts.tips" ng-show="key == tipsIndex">
{{key}}
{{value}}
<br>
<div class="keys">
{{Object.size(parts.tips)}}
</div>
</div>
<button ng-click='decrement()'>Previous</button>
<button type="button" class="btn btn-next" ng-click="increment(3)">Next</button>
</span>
</li>
</div>
</ul>
</li>
</div>
</ul>
</ul>
</div>
</body>