c#
  • jquery
  • html
  • asp.net-mvc
  • razor
  • 2016-09-22 51 views 1 likes 
    1

    请参考下面的代码。 如果.refinement选项没有孩子(品牌选项),我想显示#非字母表。 我该怎么做?根据条件显示div(ul是否有孩子)

    *请参阅下面的进一步说明。

    <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> 
    

    enter image description here

    在“#”选项卡中任何选项,所以我想“#”被转移或者隐匿的,如果它是空的 No options in '#' tab, there

    我没有使用NG-这样的事情显示,但它没有按预期工作。请纠正我。

    在控制器

    $scope.showLetter = function() { 
         if ($('.brand-option').length == 0){ 
          return false; 
         } 
    
         return true; 
        }; 
    

    标记

    <div class="list-item" id="non-alphabet" ng-show="showLetter()"><a ng-class="{active : isAlphabetSelected('#')}" ng-click="filterBrand('#')" ng-disabled="">#</a></div> 
    
    +0

    ng-repeat中的项目是什么样子? – garethb

    +0

    @garethb这是可用的选项,以相应的字母开头。 –

    回答

    1

    使用NG秀上可以算出显示还是不是一个函数股利。

    <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; 
    } 
    
    +0

    谢谢你的回答。但我想隐藏“#非字母表”div(@foreach之前的行) –

    +0

    我试过使用ng-show(请参阅上面编辑的帖子),但没有按预期工作。希望你的帮助。谢谢。 –

    +0

    查看更新。希望这会起作用 – garethb

    相关问题