2015-02-23 164 views
0

我打電話給rest服務,基於regInventoryId我想顯示與對象數組關聯的數據我能夠顯示一些對象,但有些我不能,從下面的代碼例如我無法在視圖中填充數據爲SubpartId。請讓我知道我在做什麼錯誤,歡迎任何暗示。如何從Angularjs中的對象數組中檢索數據?

見代碼遠遠低於試過......

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" 
+0

是你的數據對象的數組?我看到索引0在json – 2015-02-23 16:59:33

+0

是的它是一個數組 – aftab 2015-02-23 17:00:12

+0

嘗試:'$ scope.lrrDetail = response.data [0];' – 2015-02-23 17:01:03

回答

1

首先,如果你做了很多這種類型的查找,然後過濾式操作的,你應該結帳Underscore.js。這是一個超級有用的圖書館。然後你可以使用它的_.findWhere()功能,像這樣(我打電話給你的json.js陣列json1爲清楚起見):

$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'); 
    }); 
} 

這將返回第一個匹配的json1陣列英寸現在,從json2數組中獲取正確值的語法可能會有所不同,但只需嘗試console.log(response.data),直到找到要查找的值。例如,你可以嘗試像。 console.log(response.data[0].id);

+0

非常感謝您給我提供建議! – aftab 2015-02-24 15:00:24