如何中断或继续 Ext.each [英] How to break or continue Ext.each

查看:16
本文介绍了如何中断或继续 Ext.each的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ext.each(boundsExtend, function(value)
{
    if(value != record.ID) break;
});

那么如何中断或继续 Ext.each 循环?

So how do I break or continue Ext.each loop?

推荐答案

来自 文档:

如果提供的函数返回false,迭代停止,此方法返回当前索引.

If the supplied function returns false, iteration stops and this method returns the current index.

就像在 OP 的示例中一样(假设 record 在范围内且非空):

So as in the OP's example (assuming record is in scope and non-null):

Ext.each(boundsExtend, function(value) {
  if (value != record.ID) {
    return false;
  }
  // other logic here if ids do match
});

请注意,返回 false 会完全退出循环,因此在这种情况下,第一个不匹配的记录将绕过任何额外的检查.

Note that returning false exits the loop completely, so in this case the first non-matching record will bypass any additional checking.

但是我猜你真正想做的是循环直到你找到匹配的记录,做一些逻辑,然后短路循环.如果是这样的话,逻辑实际上是:

However I'm guessing that what you're really trying to do is loop until you find the matching record, do some logic, then short-circuit the loop. If that's the case, the logic would actually be:

Ext.each(boundsExtend, function(value) {
  if (value === record.ID) {
    // do your match logic here...
    // if we're done, exit the loop:
    return false;
  }
  // no match, so keep looping (i.e. "continue")
});

任何其他未明确false的值(例如,默认情况下为null)将继续循环.

Any other value that is not explicitly false (e.g. null by default) will keep the loop going.

这篇关于如何中断或继续 Ext.each的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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