2014-11-06 2 views
0

ng-grid을 사용하고 있는데 그리드 테이블의 데이터가 변경되면 자동으로 단일 모델을 업데이트하려고합니다. 그 때문에 나는 ng-grid의 편집 모듈을 사용하고 있습니다.ng-grid - 편집 후 원격 업데이트. 방법?

# Define app 
app = angular.module("app", ["ng-rails-csrf", "rails", 'ngTagsInput', 'ui.bootstrap', 'ui.grid', 'ui.grid.edit']) 


app = angular.module("app") 

app.controller "UsersController", ["$scope", "User", ($scope, User)-> 
    $scope.init = -> 
    User.query({}).then((results)-> 
     console.log results 
     $scope.gridOptions.data = results 
) 

    $scope.gridOptions = 
    enableFiltering: true 
    columnDefs: [ 
     {field: 'id'} 
     {field: 'email', enableCellEdit: true, type: 'string'} 
     {field: 'firstName', enableCellEdit: true, type: 'string'} 
     {field: 'lastName', enableCellEdit: true, type: 'string'} 
     {field: 'lastName', enableCellEdit: true, type: 'string'} 
    ] 

    $scope.init() 

    $scope.$watch 'gridOptions.data', (newValue, oldValue)-> 
    console.log "new value" 
    console.log newValue 
    console.log "old value" 
    console.log oldValue 
    # FIXME this causes a lot of updates to the remote 
    , true 
] 

html: 
.users-list 
    .my-grid ui-grid="gridOptions" ui-grid-edit="ui-grid-edit" 

그것을 할 수있는 더 좋은 방법이 있나요 :

이 내 컨트롤러의 코드는? 모델 중 하나가 변경 될 때마다 업데이트 기능 호출?

+0

$ watchCollection'봐()'은'$ 시계 대 (FUNC .. TRUE '는 깊은 연결이 – Dylan

+0

내 코드에서 그 변화가? 그것은 덜 자주 호출 할 것입니다 무엇? 감사합니다! – Hendrik

+0

여기에 대한 그들에 관한 좋은 기사 -http : //teropa.info/blog/2014/01/26/the-three-watch-depths-of-angularjs.html – Dylan

답변

0

각도 디 바운스 (angular debounce)를 어디에서 사용할 수 있는지, 그리드의 모델에 어떻게 적용되는지 모르겠습니다.

어쩌면 무엇인가?

<input ng-model="gridOptions.data" ng-model-options="{debounce: {'default': 700} }"/> 

로다시/밑줄은 다음과 같습니다.

$scope.$watch('gridOptions.data', _.debounce(function (value) { 
    $scope.$apply(function(){ 
     ... 
    }) 
}, 700));