我在控制器中有两个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"
},
];
第二个json数据:
$scope.myData = [{name: "Moroni", id: 1},
{name: "Tiancum", id: 2},
{name: "Jacob", id: 3},
{name: "Nephi", id: 4},
{name: "Enos", id: 5}];
我如何将第一个sid
与对象数据进行比较与angularjs中第二个对象数据的id
匹配
答案 0 :(得分:1)
if ($scope.fetchAllCenters[0].sid === $scope.myData[1].id)
{
alert("sid of first fetchAllCenters is equat to id of myData ");
}