Value
이 Key
인 객체를 AngularJs 응용 프로그램에서 md-select를 사용하여 선택한 객체에서 가져 오는 데 문제가 있습니다. 버전 1.XX).md-select를 사용하여 개체에서 키 값을 가져 오는 중 문제가 발생했습니다. AngularJs 1.XX
두 개의 드롭 다운 "Department
"과 "Designation
"이 있습니다. 처음에 부서를로드하고 부서 선택에 따라 지정이 자동으로 채워집니다. 좋은 말 좋은 말
{
"Status":true,
"Message":"",
"Result":[
{
"DepartmentId":1,
"Name":"Bala",
"Designation":[
{
"DesignationId":1,
"DepartmentId":1,
"Name":"Software Engg"
},
{
"DesignationId":3,
"DepartmentId":1,
"Name":"Sr. Human Resouce"
},
{
"DesignationId":2,
"DepartmentId":1,
"Name":"Sr. Software Engg"
}
]
},
{
"DepartmentId":2,
"Name":"Dev",
"Designation":[
]
},
{
"DepartmentId":3,
"Name":"HR Team",
"Designation":[
]
},
{
"DepartmentId":4,
"Name":"Sales",
"Designation":[
{
"DesignationId":4,
"DepartmentId":4,
"Name":"Sr. Sales Manager"
}
]
}
]
}
는 내가 선택한 항목의 DepartmentId
및 DesignationId
를 표시하기 위해 노력하고있어
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.1/angular-material.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-animate.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-aria.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-messages.min.js"></script>
<!-- Angular Material Library -->
<script src="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.1/angular-material.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<p>Department:</p>
<md-select ng-model="select.Department" tabindex="9" ng-change="onChange(select.Department)">
<md-option ng-repeat="key in loadUpData.Department" value="{{key}}">{{key.Name}}</md-option>
</md-select>
<p>Department ID:</p>
<md-input-container class="md-block">
<input type="text" ng-model="select.Department.DepartmentId" maxlength="300" tabindex="32" />
</md-input-container>
<br/>
<p>Designation:</p>
<md-select ng-model="select.Designation" tabindex="9">
<md-option ng-repeat="key in designationData" value="{{key}}">{{key.Name}}</md-option>
</md-select>
<p>Designation ID:</p>
<md-input-container class="md-block">
<input type="text" ng-model="select.Designation.DesignationId" maxlength="300" tabindex="32" />
</md-input-container>
</div>
<script>
var app = angular.module('myApp', ['ngMaterial']);
app.controller('myCtrl', function($scope) {
$scope.loadUpData = {
Department: angular.fromJson("{" +
" \"Status\":true," +
" \"Message\":\"\"," +
" \"Result\":[" +
" {" +
" \"DepartmentId\":1," +
" \"Name\":\"Bala\"," +
" \"Designation\":[" +
" {" +
" \"DesignationId\":1," +
" \"DepartmentId\":1," +
" \"Name\":\"Software Engg\"" +
" }," +
" {" +
" \"DesignationId\":3," +
" \"DepartmentId\":1," +
" \"Name\":\"Sr. Human Resouce\"" +
" }," +
" {" +
" \"DesignationId\":2," +
" \"DepartmentId\":1," +
" \"Name\":\"Sr. Software Engg\"" +
" }" +
" ]" +
" }," +
" {" +
" \"DepartmentId\":2," +
" \"Name\":\"Dev\"," +
" \"Designation\":[" +
" ]" +
" }," +
" {" +
" \"DepartmentId\":3," +
" \"Name\":\"HR Team\"," +
" \"Designation\":[" +
" ]" +
" }," +
" {" +
" \"DepartmentId\":4," +
" \"Name\":\"Sales\"," +
" \"Designation\":[" +
" {" +
" \"DesignationId\":4," +
" \"DepartmentId\":4," +
" \"Name\":\"Sr. Sales Manager\"" +
" }" +
" ]" +
" }" +
" ]" +
"}").Result
};
$scope.Select = {
Department: {},
Designation: {}
};
$scope.onChange = function(selected) {
var Designation = JSON.parse(selected).Designation;
console.log(Designation);
$scope.designationData = Designation;
};
});
</script>
</body>
</html>
코드를보고있는 JSON 객체로 모양을 가지고 있지만, 나는 이드를 얻을 수 없다. 친절하게 도와주세요. 고정 필요