aftab
aftab

Reputation: 545

How to retrieve data from Array of Object in Angularjs?

I am calling rest service, based on regInventoryId i want to display data that are associated with the array of object i was able to display some objects but some i could not ,From code below for example i could not populate data in the view for SubpartId. Please let me know what i am doing wrong any suggetion will be welcome.

See code Below tried so far...

HTML

<div class="row">
        <div class="col-md-6">
            <h5>
                <strong>Rule Id</strong>
            </h5>
            <div>{{lrrDetail.ruleIdentifier}}</div>
        </div>
        <div class="col-md-6">
            <h5>
                <strong>SubpartID</strong>
            </h5>
            <div>{{lrrDetail.subPartId}}</div>
        </div>
    </div>
    <hr class="modalHr"></hr>
    <div class="row lrrDetailboxMrgn">
        <div class="col-md-6">
            <h5>
                <strong>Rule Internal or Outsourced</strong>
            </h5>
            <div>Rule internal data</div>
        </div>
        <div class="col-md-6">
            <h5>
                <strong>Subpart Internal or Outsourced</strong>
            </h5>
            <div>LRR Data one lorem ipsum</div>
        </div>
    </div>

CTRL.JS

  $scope.lrrDetailWinOptions = lrrSearchGridConfig.modalLrrConfig;
    $scope.showDetail = function (id){
      $scope.selectedId = id;
      lrrDetails.findlrrDetail(id.regInventoryId).then(function(response){
        $scope.lrrDetail = response.data;
        $scope.$broadcast('openDetailWindow');
      });

    }

FACTORY.JS

  findlrrDetail: function(regInventoryId){
        return $http.get('/third-party-management/rest/lrr/' + regInventoryId);
    },

};

JSON.JS

0: {subPartId: "99996", regInventoryId: 38468, citationId: "94181", coreCitationId: "69502",…}
assigned: false
citationId: "94181"
citationValue: "New Jersey Statutes 46"
coreCitationId: "69502"
issuingAuth: "New Jersey Legislature"
regInventoryId: 38468
regInvetoryName: "Document Signing & Notary"
regInvetoryNameKey: 4074
regionName: "United States,"
ruleIdentifier: "17181"
ruleName: "Property"
subPartId: "99996"
subPartRuleInvortyKey: null
subpartCitation: "New Jersey Statutes 46:14-6.1"
subpartRuleName: null

JSON1.JS

applicabilityIndicator: "0"
auditGroupCategory: null
auditGroupIndicator: "0"
citationAsOfDate: 1385355600000
citationCoreIndicator: "69498"
citationValue: "New Jersey Statutes 46"
createdBy: "ERDSYSTEM"
createdDate: 1387240599333
enterpriseReportingHierarchies: []
externalIndintifier: "94177"
geographicLocations: [{id: 5670, sourceFeedKey: 5, lookupCode: "RS_ACTIVE", externalIndintifier: "226",…}]
0: {id: 5670, sourceFeedKey: 5, lookupCode: "RS_ACTIVE", externalIndintifier: "226",…}
highValueSummary: "Title 46 of the New Jersey statutes provides property laws."
id: 38468
issuingAuthority: {id: 13853, agencyCode: "NJ Leg", agencyName: "New Jersey Legislature",…}
agencyCode: "NJ Leg"
agencyName: "New Jersey Legislature"
id: 13853
issuingAuthName: "New Jersey Legislature"
lookupCode: "RS_ACTIVE"
modifiedDate: 1421072858363
mofifiedBy: "ERDSYSTEM"
regInventoryRuleSubPart: null
regulatoryInventoryClassfication: {id: 8001, classificationName: "Compliance", sponserWrokerKey: 209161}
classificationName: "Compliance"
id: 8001
sponserWrokerKey: 209161
regulatoryInventoryName: {id: 4074, inventoryName: "Document Signing & Notary", erhKey: 17844, regInvetoryclassKey: 8001}
erhKey: 17844
id: 4074
inventoryName: "Document Signing & Notary"
regInvetoryclassKey: 8001
ruleIdentifier: "17181"
ruleName: "Property"
sourceFeedKey: 15
subpartCitationCount: 4
subpartCitationIndicator: "0"
subpartCount: 4
vedourActivityDescription1: null
vedourActivityDescription2: null
vedourActivityType: "Both"

Upvotes: 0

Views: 2093

Answers (1)

n_i_c_k
n_i_c_k

Reputation: 1534

First, if you do a lot of this type of find-then-filter type of operations, you should checkout Underscore.js. It's a super useful library. Then you can use it's _.findWhere() function like so (i'm calling your json.js array json1 for clarity):

$scope.lrrDetailWinOptions = lrrSearchGridConfig.modalLrrConfig;
  $scope.showDetail = function (id){
    $scope.selectedId = id;
      lrrDetails.findlrrDetail(id.regInventoryId).then(function(response){
      $scope.json2 = response.data;
      $scope.lrrDetail = _.findWhere($scope.json1, {'regInventoryId':$scope.json2.id});
      $scope.$broadcast('openDetailWindow');
  });
}

This will return the first match in the json1 array. Now the syntax to get the correct value from json2 array might be different for you, but just experiment with console.log(response.data) until you find the value you're looking for. For example, you could try like. console.log(response.data[0].id);

Upvotes: 1

Related Questions