javascript - I can populate ServiceType but can't get the right values for ServiceName(dependent drop down list) -
how can have right servicename dropdown values based on servicetype dropdown selected values.
$scope.servicetypeandname = [ { "id":0, "type":"", "list":"" }, { "id":1, "type":"in-person", "list":["adl functional assessment", "community functional assessment", "future care cost analysis"] }, { "id":2, "type":"paper review", "list":["ot - in home assessment - abi", "ot - in home assessment attendant care form 1", "ot - occupational therapy assessment"] }, { "id":3, "type":"administration", "list":["situational assessment", "situational assessment (ot) - day 1", "situational assessment (ot) - day 2", "construction cost consulting"] } ]; $scope.selectedline = [{"event_id": "100", "service_type": "in-person", "service_name": "community functional assessment"}, {"event_id": "101", "service_type": "paper review", "service_name": "ot - occupational therapy assessment"},{"event_id": "102", "service_type": "in-person", "service_name": "future care cost analysis"}];
<select ng-model="selectedline.service_type" name="servicetype" class="form-control"> <option ng-repeat="temp in servicetypeandname" value="{{temp.type}}">{{temp.type}}</option> </select> <select ng-model="selectedline.service_name" name="servicename" ng-required="selectedline.service_type!=''" class="form-control"> </select>
for example, if load first object value "in-person" should selected in first dropdown , value "community functional assessment" should selected in second dropdown along corresponding list values , if change first dropdown corresponding list values should populated in second dropdown.
your data structured in way not make easiest, still isn't worst:
basically need find out object in servicetypeandname
array matching on. requires filter:
$scope.selectedlinechanged = function () { $scope.selectedservicetypeandname = $filter('filter')($scope.servicetypeandname, $scope.selectedline.service_type)[0]; };
here's thing: don't know how plan on loading selected items, ones store in selectedlines
array. load items via select box in plnkr.
when top box changed, matches remaining two.
Comments
Post a Comment