使用angularjs以JSON格式获取特定数据

时间:2017-03-30 10:34:07

标签: angularjs

我正在以某种方式获取JSON格式。但我想只获取JSON格式的特定数据。

这是我的代码。

<tbody>
    <tr ng-repeat="x in studyTeamObj" align="center">
    <td>
      <select class="form-control" ng-model="x.designation" ng-options="item as item.Emp_Name for item in createStudyObj.Study_User">
        <option value=""></option>
      </select>
    </td>
    <td>
      {{x.designation.Emp_Id}}
    </td>
    <td>
      {{x.designation.Designation}}
    </td>
    <td class="mdrf-add-row-col">
      <i class="fa  fa-minus-circle" data-ng-click="deleteMem($index)"></i>
    </td>
  </tr>
</tbody>

这是我的控制器。

$scope.studyTeamObj = [
    { }
];

$scope.addStudyTeam = function () {
    $scope.studyTeamObj.push({
        designation:'', 
    });
}

var formList = [];
formList.push(                                
    { Study_Team: $scope.studyTeamObj },                
);

添加时我得到了这种json格式

{
  "Study_Team": [
    {
      "designation": {
        "Emp_Name": "mdrf",
        "Emp_Id": 2,
        "Designation": "Research Dietitian",
        "DesignationID": 20
      }
    }
  ]
}

但我需要这样,

{
  "Study_Team":[
    {
      "Study_Id":"1",
      "DesignationID":"20",
    }
  ]
}

有人可以帮忙吗?

createStudyService.saveStudy(data).then(function (response) 
{ if (response.data === 'Study Master Saved Successfully') 
{ alertService.showDialog('md', 'Message', 'Study has been created', 'success', 'studyList');
 } else
 { alertService.showDialog('sm', 'Alert', 'Study Details Not Added Successfully', 'warning'); } 

1 个答案:

答案 0 :(得分:0)

createStudyService.saveStudy(data).then(function (response)  
{ 
if (response.data === 'Study Master Saved Successfully')
{ alertService.showDialog('md', 'Message', 'Study has been created', 'success', 'studyList');
} else 
{ alertService.showDialog('sm', 'Alert', 'Study Details Not Added Successfully', 'warning'); } }