为每个元素

时间:2015-11-19 13:17:33

标签: javascript jquery angularjs ionic-framework

我在日历上工作,点击日期我应该看到一个列表,但点击后我看到所有列表由于ng-repeat而且我给了动态类和id给日期,行和列表反映在html中很好但是在使用jquery attr(' class')时它对所有日期,行和列表显示相同

正如您在打印课程时所看到的,它为每个元素打印相同的类day0但在检查元素时显示不同的类day0和day1

模板 -

<div ng-controller="calendarCtrl">
<div id="w{{$index}}" class="row weeks" ng-repeat="week in weeks" ng-controller="calendarCtrl">
    <div style="display:flex;" class="col" id="r{{$index}}">
        <span id="{{day.number}}" class="day {{'day' + day.number}} col" ng-class="{today: day.isToday,'different-month': !day.isCurrentMonth, selected:day.date.isSame(selected)}" ng-click="select(day)"  ng-repeat="day in week.days">
            {{day.number}}      
        </span>
    </div>
    <!-- appointment list    -->
    <div ng-show="dateFlag" class="list listPos" id="l{{$index}}">
        <div class="item-divider">Appoitnments</div>
        <div class="item">1</div>
        <div class="item">2</div>
        <div class="item">3</div>
        <div class="item">4</div>
    </div>

</div>

控制器 -

 scope.select = function(day) {
     console.log(day);

     scope.selected = day.date;  
     scope.dateFlag = ! scope.dateFlag;

     jQuery(document).ready(function($){
         console.log($('.day').attr("class"));
     });                 
 };

1 个答案:

答案 0 :(得分:0)

因为您正在迭代weeks并附加与周无关的day.numberday.number的值在所有迭代中都是相同的。

如果需要,您可以附加$index,以便类名称后缀为$index