如何比较NG重复内的值。? [英] How to compare values inside ng-repeat.?

查看:105
本文介绍了如何比较NG重复内的值。?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要比较在值NG-重复。如何previous值里面当前值NG-重复进行比较。我有一个数组,其值[2,3]。我想与首次比较阵列第二个值。怎么办呢?结果
更新:我目前显示月,日和接下来的七天。现在,如果在未来七天有新的一个月,我的意思是在一月份12月以后,我只需要这个月的日期之前,包括这个月。结果
防爆:: 周二月30日,星期三31月1星期四,星期五2 ....

所有code是在这里:小提琴: http://jsfiddle.net/HB7LU/9763/

 < D​​IV CLASS =行的风格=文本对齐:中心;背景颜色:#930d14;颜色:白色;高度:55像素;>
            < D​​IV CLASS =山坳的风格=BORDER-右:1px的固体#820d13;>
                < p =风格改造:旋转(270deg)的margin-top:8像素; FONT-SIZE:10px的;字体重量:600;文本转换:大写;>
                    {{currentMonth}}&下; / P>
            < / DIV>
            < D​​IV CLASS =山坳的风格=BORDER-右:1px的固体#820d13; NG-重复=天totalDays.aryDates>
                < p =风格FONT-SIZE:10px的;字体重量:500;> {{天}}< / P>
                < p NG-IF =totalDays.aryDates [$指数1] == totalDays.aryDates [$指数]!的风格=改造:旋转(270deg)的margin-top:8像素; FONT-SIZE:10px的;字体重量:600;文本转换:大写;>
                    {{newMonth}}&下; / P>
            < / DIV>


解决方案

Angular.js回路有$指数。您可以使用

 < D​​IV NG重复=项中的项目>
     <跨度NG秀=项目[$指数1] ==项目[$指数]>< / SPAN>
    < / DIV>

I need to compare values inside ng-repeat. How to compare previous value with current value inside ng-repeat. I have an array, having values [2,3]. I want to compare array second value with first. How to do it?
Update: I am displaying current month and date and next seven days. Now if in next seven days there is new month, i mean as january after december, I need to include this month just before the dates of this month.
Ex:: Dec Tue 30, Wed 31, Jan Thu 1, Fri 2 ....

All code is here: Fiddle: http://jsfiddle.net/HB7LU/9763/

 <div class="row" style="text-align:center;background-color: #930d14; color: white; height: 55px;">
            <div class="col" style="border-right: solid 1px #820d13;">
                <p style="transform: rotate(270deg);margin-top: 8px;font-size: 10px;font-weight: 600;text-transform: uppercase;">
                    {{currentMonth}}</p>
            </div>
            <div class="col" style="border-right: solid 1px #820d13;" ng-repeat="days in totalDays.aryDates">
                <p style="font-size: 10px;font-weight: 500;">{{days}}</p>
                <p ng-if="totalDays.aryDates[$index-1] !== totalDays.aryDates[$index]" style="transform: rotate(270deg);margin-top: 8px;font-size: 10px;font-weight: 600;text-transform: uppercase;">
                    {{newMonth}}</p>
            </div>

解决方案

Angular.js loops have $index. You can use

  <div ng-repeat="item in items">
     <span ng-show="items[$index-1] == items[$index]"></span>
    </div>

这篇关于如何比较NG重复内的值。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆