C# 根据条件显示div(ul是否有子项)
请参阅下面随附的代码。 如果.细化选项没有子项(品牌选项),我想显示#非字母表。 我该怎么做 *见下文的进一步解释C# 根据条件显示div(ul是否有子项),c#,jquery,html,asp.net-mvc,razor,C#,Jquery,Html,Asp.net Mvc,Razor,请参阅下面随附的代码。 如果.细化选项没有子项(品牌选项),我想显示#非字母表。 我该怎么做 *见下文的进一步解释 <div class="alphabets-container"> <div owl-carousel owl-configuration='{"items" : 27, "itemsDesktopSmall" : [992,20], "itemsTablet" : [768,10], "itemsMobile" : [479, 1
<div class="alphabets-container">
<div owl-carousel owl-configuration='{"items" : 27, "itemsDesktopSmall" : [992,20], "itemsTablet" : [768,10], "itemsMobile" : [479, 10], "itemsDesktopMedium" : [1200,27], "itemsDesktop" : false, "pagination" : false, "autoPlay" : false}'>
<div class="list-item" id="non-alphabet"><a ng-class="{active : isAlphabetSelected('#')}" ng-click="filterBrand('#')">#</a></div>
@foreach (var character in brandCategories)
{
<div class="list-item">
<a class="alphabet-option" ng-class="{active : isAlphabetSelected('@character')}" ng-click="filterBrand('@character')">@character</a>
</div>
}
</div>
</div>
<ul class="refinement-options reflex-container reflex-wrap filter-group" data-filter-type="brand">
<li class="brand-option reflex-col-3" ng-repeat="item in items | startsWithLetter:filterKey">
<input type="checkbox" class="css-checkbox" ng-checked="item.IsChecked" ng-model="item.IsChecked" id="{{ item.Id }}" name="{{ item.Name }}" value="{{ item.QueryValue }}" data-base-url="{{ item.BaseUrl }}" data-link-url="{{ item.LinkUrl }}" />
<label for="{{ item.Id }}" class="checkbox css-label">{{ item.DisplayText }} ( {{ item.HitCount }} )</label>
</li>
</ul>
标记
<div class="list-item" id="non-alphabet" ng-show="showLetter()"><a ng-class="{active : isAlphabetSelected('#')}" ng-click="filterBrand('#')" ng-disabled="">#</a></div>
#
在div上使用ng show,并使用一个函数确定是否显示
<div class="list-item" id="non-alphabet" ng-show="showHash()"><a ng-class="{active : isAlphabetSelected('#')}" ng-click="filterBrand('#')">#</a></div>
ng repeat中的项目是什么样子的?@garethb可用选项以各自的字母表开头。谢谢您的回答。但是我想隐藏“#non-alphabet”div(@foreach之前的那行),我尝试过使用ng show(见上面我编辑的帖子),但没有按预期工作。希望你的帮助。谢谢
<div class="list-item" id="non-alphabet" ng-show="showHash()"><a ng-class="{active : isAlphabetSelected('#')}" ng-click="filterBrand('#')">#</a></div>
$scope.showHash= function(){
var r = /^[^a-zA-Z]/g; //regex for not start with letter
$.each($scope.items, function(index, value){
if (r.test(value.DisplayText)){
return true;
}
});
return false;
}