如何更新角度ng网格中的行

时间:2014-03-25 03:01:56

标签: angularjs angular-ui ng-grid

我使用ng-grid,我有一个数组来存储我的数据。

$scope.list = [{...},{...},{...}]

现在我想更新一个对象(即连续)中的数据:

我尝试了$scope.list[index] = {...}并更改了其值,但HTML中没有更新任何内容。

下面的方法适合我,但我认为它们并不是那么漂亮。

arr = angular.copy($scope.list) arr[index] = {...} $scope.list = arr

$scope.list[index].attr_1 = sth; $scope.list[index].attr_2 = sthElse; ...

更新:

  $scope.pickProduct = ()->
    $scope.errorMessage = ''
    $http.post('/api/delivery_items/pick.json',
       barcode: $scope.scannedBarcode
    ).success((data, status, headers, config) ->
      $scope.scannedBarcode = ''
      angular.forEach $scope.picklist, (row, index) ->
        if row.id == data.id
          # I update the data but it doesn't change the row in HTML
          $scope.picklist[index] = data.delivery_item
    ).error((data, status) ->
      if data.status is 'nok'
        $scope.scannedBarcode = ''
        $scope.errorMessage = data.message
    )

0 个答案:

没有答案