gpt4 book ai didi

javascript - ng-change 不起作用,ng-change 后未加载数据

转载 作者:行者123 更新时间:2023-12-01 03:56:32 30 4
gpt4 key购买 nike

我添加了一个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 Controller :

'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 Controller :

@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=?

最佳答案

更改response.data仅执行response

.success(function(response){
$scope.subss = response;
}).error(function(reponse){
alert('error');
});

关于javascript - ng-change 不起作用,ng-change 后未加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42622382/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com