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

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

问题描述

$ $ $ $ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $

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

解决方案

docs


如果提供的函数返回
false,则迭代停止这个方法
返回当前索引。


所以在OP的例子中(假设记录在范围和非空):

  Ext.each(boundsExtend,function(value) {
if(value!= record.ID){
return false;
}
//其他逻辑,如果ids匹配
});

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



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

  Ext.each(boundsExtend,function(value){
if(value === record.ID){
//你的匹配逻辑在这里...
//如果我们完成,退出循环:
return false;
}
//不匹配,所以保持循环(即继续)
});

任何其他不明确的值 false (例如, null 默认情况下)将保持循环。


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

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

解决方案

From the docs:

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

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
});

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")
});

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

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

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