繁体   English   中英

如何从Angularjs中的对象数组中检索数据?

[英]How to retrieve data from Array of Object in Angularjs?

我正在基于regInventoryId调用rest服务,我想显示与对象数组相关联的数据,我能够显示一些对象,但某些我无法显示,例如,从下面的代码中,我无法在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"

首先,如果您执行了很多此类“查找-然后-过滤”类型的操作,则应签出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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM