/**
     * 判断两个数组中是否含有相同元素
     * 用于对比菜单树标签和已选标签的包含性
     * **/ 
    includeSelectTags(treetags,selecttags){
      var isExist= false;
        for (var i = 0; i < treetags.length; i++) {
        var tag = treetags[i];
        for (var j = 0; j < selecttags.length; j++) {
          var target = selecttags[j];
          if (target == tag) {
              isExist=true;
              return isExist;
          }
        }
        
      }
      return isExist;
    }

上面方法是针对简单数组,如果是复杂数组中的某个属性,可以在传入参数的时候增加属性名,分别在tag和target赋值时用属性名

includeSelectTags(treetags,selecttags,keyname){
...
var tag = treetags[i][keyname];
var target = selecttags[j][keyname];
...
}

charlotteeeeeee
74 声望7 粉丝