2016-11-24 27 views
0

不必要的角度值鏈接

圖爲一個編輯頁面,可以使用的命令添加到列表,刪除等。當用戶單擊更新按鈕時,該值只應更新爲實際數組。下面是我的一些代碼:

$scope.editSchedule = function(index){ 
       console.log(index); 
     $scope.editScheduleValue = { 
     name: $scope.currentSchedule[index].name, 
     trigger: $scope.currentSchedule[index].trigger, 
     repeat: $scope.currentSchedule[index].repeat, 
     commandList: $scope.currentSchedule[index].commandList, 
     scheduleIndex: index 
     }; 
     var dailog = $uibModal.open({ 
      templateUrl: 'app/partials/edit-schedule.html', 
      controller: editScheduleController, 
      size: 'lg', 
      scope: $scope 
     }); 
    }; 

這是一個編輯按鈕的範圍,這將得到curremtSchedule陣列的實際值。

$scope.addCommand = function(){ 
    console.log("addCommand"); 
    $scope.addRoom = $scope.equipment[$scope.roomSelected].name; 
    $scope.addEquipment = $scope.equipment[$scope.roomSelected].equipment[$scope.equipmentSelected].name; 
    $scope.addEquipmentCommand = $scope.equipment[$scope.roomSelected].equipment[$scope.equipmentSelected].command[$scope.commandSelected].type; 
    $scope.editScheduleValue.commandList.push({ 
     room: $scope.addRoom, 
     equipment: $scope.addEquipment, 
     command: $scope.addEquipmentCommand 
    }) 
    }; 

這是我的添加命令按鈕代碼,它將數據推送到editScheduleValue數組。

HTML:

<tr ng-repeat="x in editScheduleValue.commandList" ui-tree-node> 
     <td style="width: 5%"><i class="glyphicon glyphicon-resize-vertical" ui-tree-handle></i> </td> 
     <td style="width: 5%">{{$index+1}}</td> 
     <td style="width: 30%">{{x.room}}</td> 
     <td style="width: 30%">{{x.equipment}}</td> 
     <td style="width: 30%">{{x.command}}</td> 
     <td> 
     <a class="pull-right btn btn-danger btn-xs" data-nodrag ng-click="remove(this)"> 
      <span class="glyphicon glyphicon-remove"></span> 
     </a> 
     </td> 
     </tr> 

我encouter是每當我刪除,添加命令不僅editScheduleValue陣列更新,但currentSchedule陣列以及這個問題,我真不明白這是爲什麼2數組以某種方式鏈接。請幫忙~~~ 謝謝。

+0

你的更新功能在哪裏? – superUser

+0

Suzo,我還沒有寫我的更新功能代碼呢。 –

回答

0

我更換

commandList: $scope.currentSchedule[index].commandList,

隨着

commandList: angular.copy($scope.currentSchedule[index].commandList), 

這2個陣列連接不上了,我不太明白爲什麼要這樣,但這裏的回答我的問題。