为了账号安全,请及时绑定邮箱和手机立即绑定

​jquery和underscore中这个each方法

​jquery和underscore中这个each方法

qq_小树_6 2017-08-31 10:11:17
  afterAjax: function(list) {             if (list.length > 0) {                 _.each(list, function(v, i) {                     if (v.flag == 0) {                         v.flag = "否";                     } else if (v.flag == 1) {                         v.flag = "是";                     };                 });             }             return list;         },     在这个里面的each方法便利这个list集合,回调函数中第一个参数不应该是索引吗??     $.each(this.tableModel.model, function(i, v) {                 columns.push({                     title: v.name,                     data: v.code,                     width: v.width,                     "visible": v.visible === false ? false : true,                     className: v.className,                     "render": v.render,                     "targets": i + startTarget + 1                 });                 that.column.push(v.code);             });       在这里面的回调函数第一个参数i应该是索引吧?
查看完整描述

1 回答

?
橋本奈奈未

TA贡献436条经验 获得超108个赞

jquery的each的回调的第一个参数是索引没错

查看完整回答
反对 回复 2017-08-31
  • qq_小树_6
    qq_小树_6
    哈哈哈,又看到你了 ,但是我在看一个项目源码的时候underscore的each方法竟然回调函数第一个不是索引的
  • 橋本奈奈未
    橋本奈奈未
    嗯嗯,是的,underscore的api就是这么设计的。其实这样的形式js原生的foreach也是一样的
  • 1 回答
  • 0 关注
  • 1364 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信