我在课程data-ng-change='getSubjectsClasswise(classBean.class_id);'
标记中添加了<select>
,但未在主题<select>
标记处加载主题。
一切都很好,没有问题,请帮帮我。
JSP:
<div data-ng-controller='ChapterController'>
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-3">Select Class * :</label>
<div class="col-sm-8">
<div class="col-sm-6">
<select data-ng-model='classBean.class_id' data-ng-change='getSubjectsClasswise(classBean.class_id);' class="form-control" name='stdClass' required>
<option value="">--SELECT--</option>
<option data-ng-repeat='c in clss' value="{{ c.class_id}}">{{ c.class_name}}</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Select Subject * :</label>
<div class="col-sm-8">
<div class="col-sm-6">
<select data-ng-model='sid' class="form-control" required>
<option value="">--SELECT--</option>
<option data-ng-repeat='s in subss' value="{{ s.sid}}">{{ s.subject_name}}</option>
</select>
</div>
</div>
</div>
<div class="btn-right">
<button type="submit" value="Register" class="btn btn-primary">Register</button>
</div>
</form>
JS控制器:
'use strict';
var app = angular.module("CareerTurn");
app.controller('ChapterController', function($scope, $http, $location, $window, AdminService) {
getClasses();
function getClasses() {
$http({
method : 'GET',
url : 'http://localhost:8015/CareerTurn/adm/getClasses.do'
}).then(function successCallback(response) {
$scope.clss = response.data;
}, function errorCallback(response) {
console.log(response.statusText);
});
}
$scope.getSubjectsClasswise = function(class_id) {
alert(class_id);
var URL ='http://localhost:8015/CareerTurn/adm/getClasswiseSubjects.do';
$http.post(URL,class_id).success(function(response){
$scope.subss = response.data;
}).error(function(reponse){
alert('error');
});
}
});
Java控制器:
@RequestMapping(value="/getClasswiseSubjects.do", method=RequestMethod.POST)
public @ResponseBody List<SubjectBean> getClasswiseSubjects(@RequestBody int class_ids) {
return getAdminService().getClasswiseSubjects(class_ids);
}
@RequestMapping(value="/getClasses.do", method=RequestMethod.GET)
public List<ClassBean> getClasses() {
return getAdminService().getClasses();
}
DaoImpl:
@Override
public List<ClassBean> getClasses() {
try{
String sql="from ClassBean";
query = em.createQuery(sql);
return query.getResultList();
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
@Override
public List<SubjectBean> getClasswiseSubjects(int class_id) {
try{
query = em.createQuery("from SubjectBean sb where sb.classBean.class_id=:class_id");
query.setParameter("class_id", class_id);
List<SubjectBean> subs = query.getResultList();
return subs;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
控制台:
Hibernate: select classbean0_.class_id as class1_1_, classbean0_.class_createdate as class2_1_, classbean0_.class_createdby as class3_1_, classbean0_.class_name as class4_1_ from exam_class classbean0_
Hibernate: select subjectbea0_.sid as sid26_, subjectbea0_.class_id as class6_26_, subjectbea0_.subject_code as subject2_26_, subjectbea0_.subject_createdate as subject3_26_, subjectbea0_.subject_createdby as subject4_26_, subjectbea0_.subject_name as subject5_26_ from subjects_tbl subjectbea0_ where subjectbea0_.class_id=?
答案 0 :(得分:2)
更改response.data
只做response
.success(function(response){
$scope.subss = response;
}).error(function(reponse){
alert('error');
});