2016-09-06 2 views
0

私は固執していて、このコードをどのように処理するのか分かりません。私は要件に応じてhtmlを変更しましたが、Ajaxレスポンスの後、Angula Jsのオブジェクト値を再初期化することはできません。誰でも助けてもらえれば、私は彼に感謝します。html ng-repeatオブジェクトごとにAngularJsオブジェクトをr-初期化できませんか?

<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]応答を待っている

おかげ&定義されていません。

+1

を?変数を変更すると、HTMLが変更に従います。 –

+0

実際に私の要求に応じてhtmlを変更しましたが、ajax呼び出し後にエラーを返すためjsを変更できません。エラーが発生しています –

答えて

0

問題の原因はわかりませんが、機能を終了していません。

$scope.saveEditSub = function(id){ 
+0

エラーを説明しました。私は正しいオブジェクト値をAjax呼び出しの後に渡すことができません –

0

このような検証ください:

if(!$scope.classSchedule[response.dayOfWeek]){ 
    $scope.classSchedule[response.dayOfWeek] = { 
     schedule: {sub : [] } 
    } 
} 

をし、コードを続行:あなたは再initalizeとはどういう意味ですか

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}); 
+0

私は今、試してみましょう –

+0

私はあなたのコードを試して、値を更新するのではなく、Ajaxによって受信された、それは空のボックスを作成しました –

+0

私はIDを使用する必要がありますか? –

関連する問題