相较于数组索引值 [英] Comparing to array index value

查看:125
本文介绍了相较于数组索引值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

imageValue时数组的长度为6。

  $ scope.imageValue = [];

imageArray的长度是73

  $ scope.imageArray = [];

我使用的,如果循环来检查是否有任何指数在 imageValue时阵列等于任何 imageArray

 为(VAR I = 0;我LT&= $ scope.names.length;我++){
    对于(VAR J = 0; J< = $ scope.imageID.length; J ++){
        如果($ scope.imageValue [I] == $ scope.imageArray [J]){
            $ scope.testArray.push($ scope.imageID [J] .bindaryData);
            的console.log($ scope.testArray);
            返回true;
        }
        否则,如果($ scope.imageValue [I]!== $ scope.imageArray [J]){
            返回false;
        }    }
}

如果是的话我一定要空数组中推 bindaydata testArray

  $ scope.testArray = [];

我在所有code看起来像

  angular.module('ob3App.lead')
    .controller('LeadProductCtrl',['$范围,$ HTTP,filterFilter',函数($范围,$ HTTP,filterFilter){    $ scope.namegetfunction =功能(){
      $ scope.imageValue = [];
    $http.get(\"http://5.9.42.45:8080/easycloud1/org.openbravo.service.json.jsonrest/Product?l=saiy5k&p=saiy5k\")
        .success(功能(响应){
        的console.log(响应);
        $ scope.names = response.response.data;
        的console.log($ scope.names.length);
        $ scope.names.forEach(功能(IDS){
            的console.log(ids.id);
            $ scope.imageValue.push(ids.image);
        })
        $ scope.imageGetFunction();
        的console.log($ scope.imageValue);
        })
        .error(功能(响应){
            警报('错误的名字');
        });
    };
    $ scope.namegetfunction();    $ scope.imageGetFunction =功能(){
        $ scope.imageArray = [];
        $ scope.testArray = [];        $http.get(\"http://5.9.42.45:8080/easycloud1/org.openbravo.service.json.jsonrest/ADImage?l=saiy5k&p=saiy5k\")
        .success(功能(响应){
            的console.log(响应);
            $ scope.imageID = response.response.data;
            的console.log($ scope.imageID.length);            $ scope.imageID.forEach(函数(项目){
                $ scope.imageArray.push(item.id);
            })            的console.log($ scope.imageArray);            对于(VAR I = 0;我LT&= $ scope.names.length;我++){
                对于(VAR J = 0; J< = $ scope.imageID.length; J ++){
                    如果($ scope.imageValue [I] == $ scope.imageArray [J]){
                        $ scope.testArray.push($ scope.imageID [J] .bindaryData);
                        的console.log($ scope.testArray);
                        返回true;
                    }
                    否则,如果($ scope.imageValue [I]!== $ scope.imageArray [J]){
                        返回false;
                    }                }
            }
              的console.log($ scope.testArray);        })
        .error(功能(响应){
            的console.log(响应);
            警报('错误图像');
        });
    }; }]);


解决方案

检查了这一点,它工作正常。

 为(VAR indexOfProduct = 0; indexOfProduct< $ scope.productImage.length; indexOfProduct ++){
            的console.log(indexOfProduct);
            的console.log($ scope.productImage.length);
            如果($ scope.productImage [indexOfProduct]在图像配== NULL){
                    的console.log($ scope.productImage [indexOfProduct]在图像配);
                    $ scope.base64Array.push(NULL);
                    的console.log($ scope.base64Array);                }
                否则,如果($ scope.productImage [indexOfProduct]在图像配!== NULL){
                    为(VAR indexOfAdImage = 0; indexOfAdImage&下; = $ scope.imageID.length; indexOfAdImage ++){
                    的console.log(indexOfAdImage);
                        如果($ scope.productImage [indexOfProduct] ==​​图像配$ scope.imageID [indexOfAdImage] .ID){
                            的console.log($ scope.imageID [indexOfAdImage] .bindaryData);
                            $ scope.base64Array.push($ scope.imageID [indexOfAdImage] .bindaryData);
                            的console.log($ scope.base64Array);
                            打破;
                        }
                    }
                }
            }

The length of the imagevalue array is 6.

 $scope.imageValue=[];

The length of imageArray is 73.

$scope.imageArray=[];

I use for and if loop to check if any of the index in imagevalue array is equal to any of the index in imageArray .

for(var i = 0;i <= $scope.names.length;i++) {
    for(var j=0;j<=$scope.imageID.length;j++){
        if($scope.imageValue[i] == $scope.imageArray[j]) {
            $scope.testArray.push($scope.imageID[j].bindaryData);
            console.log($scope.testArray);
            return true;
        }
        else if($scope.imageValue[i] !== $scope.imageArray[j]){
            return false;
        }

    }
}

If so then I have to push the bindaydata value in the empty array testArray

$scope.testArray=[];

My over all code looks like

angular.module('ob3App.lead')
    .controller('LeadProductCtrl',['$scope','$http','filterFilter', function($scope,$http,filterFilter) {

    $scope.namegetfunction = function() {
      $scope.imageValue=[];
    $http.get("http://5.9.42.45:8080/easycloud1/org.openbravo.service.json.jsonrest/Product?l=saiy5k&p=saiy5k")
        .success(function(response) {
        console.log(response);
        $scope.names = response.response.data;
        console.log($scope.names.length);
        $scope.names.forEach(function(ids){
            console.log(ids.id);
            $scope.imageValue.push(ids.image);
        })
        $scope.imageGetFunction();
        console.log($scope.imageValue);
        })
        .error(function(response){
            alert('error in name');
        });
    };
    $scope.namegetfunction();

    $scope.imageGetFunction = function() {
        $scope.imageArray=[];
        $scope.testArray=[];

        $http.get("http://5.9.42.45:8080/easycloud1/org.openbravo.service.json.jsonrest/ADImage?l=saiy5k&p=saiy5k")
        .success(function(response) {
            console.log(response);
            $scope.imageID = response.response.data;
            console.log($scope.imageID.length);

            $scope.imageID.forEach(function(item) {
                $scope.imageArray.push(item.id);
            })

            console.log($scope.imageArray);

            for(var i = 0;i <= $scope.names.length;i++) {
                for(var j=0;j<=$scope.imageID.length;j++){
                    if($scope.imageValue[i] == $scope.imageArray[j]) {
                        $scope.testArray.push($scope.imageID[j].bindaryData);
                        console.log($scope.testArray);
                        return true;
                    }
                    else if($scope.imageValue[i] !== $scope.imageArray[j]){
                        return false;
                    }

                }
            }
              console.log($scope.testArray);

        })
        .error(function(response){
            console.log(response);
            alert('error in image');
        });
    };

 }]);

解决方案

check this out it works fine

for(var indexOfProduct = 0;indexOfProduct< $scope.productImage.length;indexOfProduct++){
            console.log(indexOfProduct);
            console.log($scope.productImage.length);
            if($scope.productImage[indexOfProduct].image == null) {
                    console.log($scope.productImage[indexOfProduct].image);
                    $scope.base64Array.push(null);
                    console.log($scope.base64Array);

                }
                else if($scope.productImage[indexOfProduct].image !== null) {
                    for(var indexOfAdImage =0;indexOfAdImage<=$scope.imageID.length;indexOfAdImage++){
                    console.log(indexOfAdImage);
                        if($scope.productImage[indexOfProduct].image == $scope.imageID[indexOfAdImage].id) {
                            console.log($scope.imageID[indexOfAdImage].bindaryData);
                            $scope.base64Array.push($scope.imageID[indexOfAdImage].bindaryData);
                            console.log($scope.base64Array);
                            break;
                        }
                    }    
                }
            }    

这篇关于相较于数组索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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