凸显了每个检查previous纪录 [英] Underscore check previous record in each

查看:148
本文介绍了凸显了每个检查previous纪录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在骨干网的应用程序和下划线的模板。
我想知道是否可以检查内部的每个previous记录或某事的价值进行检查。结果
假设我有记录的是这样的:
{
   ID:1,
   1级,
   jump_level:2
},
{
   ID:2,
   级别:2,
   jump_level:0
}

I have an app in backbone and a template with underscore. I want to know if is possible to check a value inside a each of the previous record or something to check.
Suppose that I have record like this: { id: 1, level:1, jump_level:2 }, { id: 2, level:2, jump_level:0 }

进入我的每一个我想检查是否previous记录有实际水平相同jump_level因为我想告诉大家,如果我有不打印下一个记录。

Into my each I want to check if previous record has the same jump_level of the actual level because I want to tell that if i have to not print next record.

这是我的一块模板:

<div>
<% _.each(room2, function(room) { %>
     //I would like to write an if like this:
     // if exist previous room -> check if jump_level == level if yes don't print span
     <span> <%= room.attributes.id %></span>                                           
<% }); %>
</div>

是可能的?
谢谢

Is possible? Thanks

推荐答案

那么你可以毫不夸张地那意思就是JS code:

Well you can quite literally translate that to JS code:

<% _.each(room2, function(room, i) {
       if ( !(i>0 && room2[i-1].jump_level == room.jump_level) ) { %>
           <span> <%= room.attributes.id %></span>
<%     }
   }); %>

这篇关于凸显了每个检查previous纪录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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