如何比较两个$ http.get并获取所需的属性

时间:2015-12-24 04:53:24

标签: angularjs ionic

我有两个函数,两个函数都有$ http.get method.first方法有response.response.data [6],第二个函数有response.response.data [76]。第一个函数有6个对象,也可用于第二个功能。比较并获取require属性

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

        $scope.namegetfunction = function() {

        $scope.products=[];
        $scope.idValue=[];    
            $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(item) {
              console.log(item.name);
             $scope.products.push(item.name);
            })

            console.log($scope.products);

$scope.names.forEach(function(ids){
            console.log(ids.id);
            $scope.idValue.push(ids.id);
        })

        console.log($scope.idValue);

            })
            .error(function(response){
                alert('error in name');
            });
        };
        $scope.namegetfunction();

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

            $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.image = response.response.data;
                console.log($scope.names.length);

                $scope.image.forEach(function(item) {
                    console.log(item.bindaryData);
                    $scope.imageArray.push(item.bindaryData);
                })
                console.log($scope.imageArray);

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

     }]);

两个函数都有一个唯一的函数,它是数组中的ID属性。借助第一个功能' ID'属性我需要调用第二个属性二进制数据属性并以离子

显示
<ion-view>
    <ion-header-bar class="bar bar-header bar-positive flat">
        <button class="button button-positive" ng-click="back()"><i class="ion-arrow-left-c"> </i></button>
        <h1 class="title">Products</h1>
    </ion-header-bar>
    <ion-content>

        <ul class="list">

            <li class="item" ng-repeat="i in products" ui-sref="leadProduct" >
                {{i}}
                <br>
                <img ng-show="imgURI === undefined" ng-src="http://placehold.it/100x100">

            </li>
        </ul>

    </ion-content>
</ion-view>

第二个功能console.log(响应)输出

response: Object
data: Array[73]
0: Object
1: Object
$ref: "ADImage/F323D8FF424E4A138D55C710768E9455"
_entityName: "ADImage"
_identifier: "Image"
active: true
bindaryData: "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAFAAPADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooooABS0gpaACiiigApaSloAKKKKACiiigAooooAKVG2tnFJSUAPds803NKRwDSUAJmjNLRQAZopKWgAozSYoxQAuaM0mDRigBc0ZpKKAHDml4poozQA2iiigApaSloAKKKSgBaUU2igB1F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4j6kv8Arba3f6ZH9a4uilZAehRfEkf8trA/VJP8RV6H4haXJ/rI7iI+pQEfoa8vpc0cqA9cj8Y6LL0vVH+8pH8xVpNd06b/AFd7Ac/7YrxnNGaXKA0UCiiqASiiigAp8bKrgsu4DqDTKUUAOJyxIAAPYdqni/1TnPaq4qWNhyD0NAEdFOZNp65FN5oAKSiigAooooAKKKKACikooAM0tJRQAuaKSigBaOKSigBfxopKWgAo59KKKACiiigBKSlNJQAUUUUAFAopaACikpccZoAliMI3ecJOR8pQjrTDkdzg0RqjOBI5Re5Azinz7fNIQ5UAAH1HrSAizRmjJxiimAUUZGOnNFABRRRQAUUAE9KKACiiigAooooAKKKKACiiigAooooAKWkooASiiigAooooAKKKKAClFJRQA4DLAdMmnSODKxX7vRfoOBTUxuG7pSHjvmgAoopKAF+nSijNJQAuOM0UCigAGe1GTQKKACgnJ6YpO9L1oABS4GBg80lJQAtKAT0puKKAFopKXOKACijNFABRQcdqKAEooooAKKKKACgcUUUAB60UUUALxjrSUUUAKOaSiigAoopc8YoASiigdaACjNFFABS5opKAFopKKAFzR3pKKAFopKKAFoxSUuaAEpaKKAEooooAKKKKAClH1pKKACiiigAxRRRQAUUo680lABRRS44zmgBKKKKACiiigAooooAB1ooooAKKKKACiiigBcUnelzSUALiigUUAf/Z"
client: "DA7A27EAF5FB4BFBBAB88EADAA3EE0A0"
client$_identifier: "Aluminium Fortune Aluminium"
createdBy: "62B215CFF490454DBE1939879A14E6CA"
createdBy$_identifier: "saiy5k - "
creationDate: "2015-10-22T12:17:28+02:00"
height: 320
id: "F323D8FF424E4A138D55C710768E9455"
imageURL: null
mimetype: "image/png"
name: "Image"
organization: "A9D87DB96C24465489ECF3C3AAF563B1"
organization$_identifier: "Fortune Aluminium"
recordTime: 1450938045552
updated: "2015-10-22T12:17:28+02:00"
updatedBy: "62B215CFF490454DBE1939879A14E6CA"
updatedBy$_identifier: "saiy5k - "
width: 320
__proto__: Object
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object
10: Object
11: Object
12: Object

第一个函数console.log(响应)输出

response: Object
data: Array[6]
0: Object
$ref: "Product/CEE73A0F92C04AF3853B12FF141CD6BB"
_entityName: "Product"
_identifier: "Wheat"
active: true
attributeSet: null
attributeSetValue: null
bOMVerified: false
billOfMaterials: false
bookUsingPurchaseOrderPrice: false
brand: null
businessPartner: null
calculated: false
capacity: null
characteristicDescription: null
classification: null
client: "DA7A27EAF5FB4BFBBAB88EADAA3EE0A0"
client$_identifier: "Aluminium Fortune Aluminium"
comments: null
costType: null
createVariants: false
createdBy: "62B215CFF490454DBE1939879A14E6CA"
createdBy$_identifier: "saiy5k - "
creationDate: "2015-08-27T10:09:45+02:00"
defaultPeriod: null
defaultPeriodExpense: null
deferredRevenue: false
description: null
descriptionURL: null
discontinued: false
discontinuedBy: null
downloadURL: null
enforceAttribute: false
expenseType: null
expplantype: null
freightCategory: null
genericProduct: null
guaranteedDays: null
helpComment: null
id: "CEE73A0F92C04AF3853B12FF141CD6BB"
image: null
imageURL: null
isGeneric: false
isdeferredexpense: false
isquantityvariable: false
manageVariants: false
maxQuantity: null
minQuantity: null
minimumLeadTime: null
minimumStock: null
name: "Wheat"
name2: null
opcrmDescription: null
opcrmUpc2: null
opcrmUpc3: null
opcrmUrl: null
organization: "A9D87DB96C24465489ECF3C3AAF563B1"
organization$_identifier: "Fortune Aluminium"
periodNumber: null
periodnumberExp: null
planner: null
planningMethod: null
printDetailsOnInvoice: false
printDetailsOnPickList: false
printPrice: true
processNow: false
processPlan: null
productCategory: "CC6FD7550F0047A8BD2CF378A4B4591A"
productCategory$_identifier: "Groceries"
productType: "I"
production: false
purchase: true
quantityType: false
recordTime: 1450938045518
resource: null
revenuePlanType: null
sKU: null
safetyStock: null
sale: true
salesRepresentative: "62B215CFF490454DBE1939879A14E6CA"
salesRepresentative$_identifier: "saiy5k"
searchKey: "WHE"
shelfDepth: null
shelfHeight: null
shelfWidth: null
standardCost: null
standardQuantity: null
stocked: true
storageBin: "AF1099E5F71D414EA52F1EC9652A6C79"
storageBin$_identifier: "Default Bin"
summaryLevel: false
taxCategory: "2BC263B831934106B12B50C6B7313E29"
taxCategory$_identifier: "Income Tax"
uOM: "72BA247D31F745F3AF11F74A5E2CCBEF"
uOM$_identifier: "Kilogram"
uOMForWeight: null
uPCEAN: null
unitsPerPallet: null
updateInvariants: false
updated: "2015-08-27T10:09:45+02:00"
updatedBy: "62B215CFF490454DBE1939879A14E6CA"
updatedBy$_identifier: "saiy5k - "
useAttributeSetValueAs: null
versionNo: null
volume: 0
weight: 0

1 个答案:

答案 0 :(得分:0)

filterFilter注入控制器功能并尝试使用以下功能。

var app = angular.module('app', ['ngAnimate']);
app.controller('LeadProductCtrl',['$scope','$http','filterFilter', function($scope,$http, filterFilter) {
    $scope.products=[];
    $scope.idValue=[];
    $scope.namegetfunction = function() {
        $scope.names = {};
        $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;
                $scope.names.forEach(function(ids){

                    $scope.idValue.push(ids.id);
                });
                $scope.imageGetFunction();
            })
            .error(function(response){
                alert('error in name');
            });


    };

    $scope.namegetfunction();

    $scope.imageGetFunction = function() {
        console.log( $scope.idValue);
        $scope.imageArray=[];
        $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);
            angular.forEach($scope.idValue, function(val, key) {
                if(filterFilter(response.response.data, {id : val})) {
                    console.log(val);
                    $scope.imageArray.push(response.response.data.bindaryData);
                }
            });
            console.log($scope.imageArray);

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