【发布时间】:2016-09-06 18:59:17
【问题描述】:
我被卡住了,不知道如何处理这段代码。我根据要求更改了html,但是在ajax响应之后,我无法重新初始化Angula Js中的对象值,如果有人能提供帮助,我将不胜感激。
<div ng-repeat="(key,sch) in classSchedule">
<h2>{{sch.sectionName}}</h2>
<table class="table table-bordered table-hover" >
<tbody>
<tr>
<th style="width: 10px">{{phrase.Day}}</th>
<th>{{phrase.ClassSchedule}}</th>
<th ng-if="userRole == 'admin'" style="width: 10px">Add</th>
</tr>
<tr ng-repeat="subSch in sch.schedule">
<td>{{subSch.dayName}}</td>
<td>
<div class="btn-group" ng-repeat="subSubSch in subSch.sub">
<button type="button" class="btn btn-default">{{subSubSch.subjectId}} - {{subSubSch.start}} -> {{subSubSch.end}}</button>
<button ng-if="userRole == 'admin'" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">{{phrase.toggleDropdown}}</span>
</button>
<ul ng-if="userRole == 'admin'" class="dropdown-menu" role="menu">
<li><a ng-click="editSubOne(subSubSch.id,key)">{{phrase.Edit}}</a></li>
<li><a ng-click="removeSub(subSubSch.id,key)">{{phrase.Remove}}</a></li>
</ul>
</div>
</td>
<td ng-if="userRole == 'admin'">
<a ng-click="addSubOne(key)" type="button" class="btn btn-info btn-flat"><i class="fa fa-fw fa-plus"></i></a>
</td>
</tr>
</tbody>
</table>
</div>
<script>
$scope.saveEditSub = function(id){
showHideLoad();
dataFactory.httpRequest('classschedule/sub/'+id,'POST',{},$scope.form).then(function(data) {
response = apiResponse(data,'edit');
if(data.status == "success"){
for (x in $scope.classSchedule[$scope.oldDay].schedule.sub) {
if($scope.classSchedule[$scope.oldDay].schedule.sub[x].id == id){
$scope.classSchedule[$scope.oldDay].schedule.sub.splice(x,1);
}
}
if(! $scope.classSchedule[response.dayOfWeek].schedule.sub){
$scope.classSchedule[response.dayOfWeek].schedule.sub = [];
}
$scope.classSchedule[response.dayOfWeek].schedule.sub.push({"id":response.id,"classId":response.classId,"subjectId":response.subjectId,"start":response.startTime,"end":response.endTime});
}
$scope.scheduleModalEdit = !$scope.scheduleModalEdit;
showHideLoad(true);
});
</script>
Ajax 调用后的错误: -> $scope.classSchedule[response.dayOfWeek] 未定义
感谢并等待回复。
【问题讨论】:
-
重新初始化是什么意思?如果您更改变量,HTML 将跟随更改。
-
其实我根据我的要求改了html,但是我不能改js,因为ajax调用后返回错误,我收到错误
标签: javascript angularjs object