2014-10-07 41 views
0

我想在表格中使用ng-repeat,並對文件夾樹結構進行排序。所以,當我點擊特定的行,並根據具體的價值,我通過「onclick」(ng-click似乎沒有工作)調用函數後更新值列表獲取JavaScript中的更新,但不反映在HTML。此外,該行甚至不顯示在HTML中。 代碼的某些部分是如下:動態列表更新ng-repeat

<tr id="parents" ng-repeat="dir in cachedDirectoryInfo.filesInPath track by dir.name"> 
               <td>{{dir.name}}</td> 
               <td>{{dir.permission}}</td> 
               <td>{{dir.modificationTime | date:'yyyy-MM-dd HH:mm'}}</td> 
               <td>{{dir.ownerName}}</td> 
               <td>{{dir.groupName}}</td> 
              </tr> 


<tr ng-repeat="child in directoryInfo.filesInPath track by child.name"> 
               <td> 
                <a id="mylink" datamylink="{{child.name}}" onclick="var myscope=angular.element($('#importCtrlEl')).scope(); myscope.hello(myscope.selectedPath, this)">{{child.name}} 
                </a> 
               </td> 
               <td>{{child.permission}}</td> 
               <td>{{child.modificationTime | date:'yyyy-MM-dd HH:mm'}}</td> 
               <td>{{child.ownerName}}</td> 
               <td>{{child.groupName}}</td> 
              </tr> 

雖然在JavaScript

$scope.hello = function (path, event) { 
      Inside promise{ 
        $scope.cachedDirectoryInfo = $scope.directoryInfo; 
        $scope.directoryInfo = hdfsResp.directoryInfo; 
      } 
} 

我看了這裏的一些解決方案,它說,使用$scope.$apply,這並不爲我工作。因爲它給我錯誤「錯誤:$ digest已在進行中」,如果我做$scope.$$phase || $scope.$apply它不會被執行。正如你所看到的,我也嘗試了ng-repeat中的track by,但沒有結果。

有沒有辦法通過jQuery來做到這一點? 我的選擇是再次替換並編譯<tr>

任何建議或解決?

PS:這是所有的jQuery步驟,這可能是一個原因。

回答

0

掙扎後,這是我能找到的解決方案。

var html = "...."; 
$("#parents").html($compile(html)($scope)); 

與範圍仍保持角部位,並更新DOM爲好。