Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在$.each中返回false在$.each中返回false_Javascript_Jquery - Fatal编程技术网

Javascript 在$.each中返回false在$.each中返回false

Javascript 在$.each中返回false在$.each中返回false,javascript,jquery,Javascript,Jquery,我使用$.each在$.each中遍历两个数组,我希望在第一个$中返回false。当第二个$中发生事件时,每个都返回false。我应该怎么做 $.each(dbFields, function(index, valuedb) { $.each(editFields, function(index, value2) { if ((valuedb.region == value2.regionField) && (valuedb.dbtype == value

我使用$.each在$.each中遍历两个数组,我希望在第一个$中返回false。当第二个$中发生事件时,每个都返回false。我应该怎么做

$.each(dbFields, function(index, valuedb) {
    $.each(editFields, function(index, value2) {
        if ((valuedb.region == value2.regionField) && (valuedb.dbtype == value2.typeField)) {
            $('#' + value2.idField).attr('id', valuedb.dbid) ; 
            $('#' + valuedb.dbid).attr('elementid', valuedb.dbid) ;                  
            console.log('Match found between ' + value2.idField + ' and '+valuedb.dbid);
            return false; //return false for the first $.each
        }
        else {
            return true ; //return truefor the first $.each
        }      
    });
});

现在,当事件返回false时,它将为第二个$返回false。每个

设置一个标志,以便外部循环知道返回false:

$.each(dbFields, function(index, valuedb) {
    var flag = true; // <=============

    $.each(editFields, function(index, value2) {
        if ((valuedb.region == value2.regionField) && (valuedb.dbtype == value2.typeField)) {

            $('#' + value2.idField).attr('id', valuedb.dbid);
            $('#' + valuedb.dbid).attr('elementid', valuedb.dbid);
            console.log('Match found between ' + value2.idField + ' and ' + valuedb.dbid);
            flag = false; // <=============
            return false; //return false for the first $.each

        } /* You don't need this ==============> else {

            return true; //return truefor the first $.each
        } */

    });

    return flag;  // <=============
});
$。每个(数据库字段、函数(索引、值数据库){

var flag=true;//设置一个标志,以便外部循环知道返回false:

$.each(dbFields, function(index, valuedb) {
    var flag = true; // <=============

    $.each(editFields, function(index, value2) {
        if ((valuedb.region == value2.regionField) && (valuedb.dbtype == value2.typeField)) {

            $('#' + value2.idField).attr('id', valuedb.dbid);
            $('#' + valuedb.dbid).attr('elementid', valuedb.dbid);
            console.log('Match found between ' + value2.idField + ' and ' + valuedb.dbid);
            flag = false; // <=============
            return false; //return false for the first $.each

        } /* You don't need this ==============> else {

            return true; //return truefor the first $.each
        } */

    });

    return flag;  // <=============
});
$。每个(数据库字段、函数(索引、值数据库){

var flag=true;//不需要
else
块。返回
true
只会继续
each()
的默认行为。不需要
else
块。返回
true
只会继续
each()的默认行为
。它有效谢谢,我不知道我怎么没有想到这样一个简单的解决方案,谢谢伙计。它有效谢谢,我不知道我怎么没有想到这样一个简单的解决方案,谢谢伙计。