我正在调用rest服务,基于regInventoryId我想显示与对象数组相关联的数据我能够显示一些对象,但有些我不能,从下面的代码中我无法填充数据SubpartId的视图。请让我知道我做错了什么,欢迎任何建议。
见代码到目前为止尝试了以下......
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 :(得分:1)
首先,如果你做了很多这种类型的find-then-filter类型的操作,你应该检查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);