2016-12-28 17 views
0

Angular JSを使用してjsonデータからカスケードドロップダウンを作成しようとしましたが、最初に選択したアイテムに基づいて2番目のドロップダウンでデータを取り込めません。 ができる任意の1 sugeest私は間違いにAngular JSを使用してjsonデータからカスケードドロップダウンを作成しようとしています

HTMLやっている私:ちょうどasset1からasset1.sectionsから二ng-options

<select ng-model="asset 1" id="assetNameGroup" ng-change="populateSection(this)"  ng-options=" x.name for x in Nameitems"> 
     <option value="">Select Name</option> 
    </select> 
    <select ng-model="asset2" id="assetNameGroup2" ng-  change="populateSection2()" ng-options=" x.name for x in asset1.sections"> 
    <option value="">Select Name</option> 
</select> 

JS

// Code goes here 
     var app = angular.module("myApp" ,[]); 
    app.controller('sensorsCtrl', function($scope, $state, $http) 
     alert(""); 

    $http.get(sample.json).success(function (resp) { 
     $scope.innerIsIsLoading = false; 
     $scope.assetData = resp; 


      $scope.Nameitems = []; 

      var testobj = $scope.assetData[0].name; 
     angular.forEach($scope.assetData, function(val,key) { 
     $scope.Nameitems.push ({"name": 
      val.name,"uri":val.uri,"sections": val.sections}); 
       console.log("console.log(JSON.stringify-----=                            "+JSON.stringify 
       ($scope.Nameitems)); 
      }); 
      console.log("$scope.assetData"+JSON.stringify($scope.assetData)); 

     $timeout(function() { 

      //$scope.SequenceLinkTableData=$scope.assetData; 
     }, 100); 
     }); 


     $scope.populateSection=function(value) 
     { 
      var checkvalue = value; 
       console.log(value); 

    var Namesite =        document.getElementById('assetNameGroup').value.split("/")[2]; 
     alert(Namesite); 
      } 

       }); 


       Json: 

        [{ 
      "uri": "/assets/0ff042ea-45e6-32e1-915b-81efa58e924e", 
     "name": "Asset 1", 
      "sections": [{ 
       "uri": "/assets/67dc7db3-2374-314d-8b19-6be09d4203c9", 
       "sectionId": null, 
    "name": "Section 1", 
    "ultrasonicSensors": null, 
    "temperatureSensors": null, 
    "ultrasonicSensorPositions": [{ 
     "ultrasonicSensorPositionId": 1392, 
     "sensorPositionName": "MeasurementPosition 1", 
     "diameter": 12, 
     "rotation": 270, 
     "sequenceNumber": null, 
     "sectionId": "/assets/67dc7db3-2374-314d-8b19-6be09d4203c9" 
    }, { 
     "ultrasonicSensorPositionId": 1428, 
     "sensorPositionName": "MeasurementPosition 2", 
     "diameter": 12, 
     "rotation": 270, 
     "sequenceNumber": null, 
     "sectionId": "/assets/67dc7db3-2374-314d-8b19-6be09d4203c9" 
    }] 
}, { 
    "uri": "/assets/8d2c61f7-eb3e-3170-9e0b-dc26b2b574f5", 
    "sectionId": null, 
    "name": "Section 1", 
    "ultrasonicSensors": null, 
    "temperatureSensors": null, 
    "ultrasonicSensorPositions": [{ 
     "ultrasonicSensorPositionId": 1390, 
     "sensorPositionName": "ultrasonic sensor position 1", 
     "diameter": 22.5, 
     "rotation": 90, 
     "sequenceNumber": null, 
     "sectionId": "/assets/8d2c61f7-eb3e-3170-9e0b-dc26b2b574f5" 
    }, { 
     "ultrasonicSensorPositionId": 1427, 
     "sensorPositionName": "MeasurementPosition 2", 
     "diameter": 12, 
     "rotation": 270, 
     "sequenceNumber": null, 
     "sectionId": "/assets/8d2c61f7-eb3e-3170-9e0b-dc26b2b574f5" 
    }, { 
     "ultrasonicSensorPositionId": 1445, 
     "sensorPositionName": "MeasurementPosition 3", 
     "diameter": 12, 
     "rotation": 270, 
     "sequenceNumber": null, 
     "sectionId": "/assets/8d2c61f7-eb3e-3170-9e0b-dc26b2b574f5" 
    }] 
}] 

     }] 

plunker link

答えて

関連する問題