我如何比较angularjs中的两个目标数据

时间:2021-09-04 12:05:18

I have two json objects in controller ,how can i match the id of first object with second json object id in angularjs first json:

我在控制器中有两个json对象,我怎样才能将第一个对象的id与angularjs中的第二个json对象id匹配为json:

$scope.fetchAllCenters= [
        {
            "sid": 1,
            "group": "Group 1",
            "name": "Item 1"
        },
        {
            "sid": 2,
            "group": "Group 1",
            "name": "Item 2"
         },
        { "sid":3,
         "group":"Group2",
         "name":"Item 3"
        },


    ];

second json data:

第二个json数据:

$scope.myData = [{name: "Moroni", id: 1},
                     {name: "Tiancum", id: 2},
                     {name: "Jacob", id: 3},
                     {name: "Nephi", id: 4},
                     {name: "Enos", id: 5}];

how can i compare sid of first with object data is matched with idof second object data in angularjs

我如何比较第一个sid和对象数据与angularjs中idof第二个对象数据相匹配

1 个解决方案

#1


1  

if ($scope.fetchAllCenters[0].sid === $scope.myData[1].id) 
{
alert("sid of first fetchAllCenters is equat to id of myData ");
}

#1


1  

if ($scope.fetchAllCenters[0].sid === $scope.myData[1].id) 
{
alert("sid of first fetchAllCenters is equat to id of myData ");
}