ng-grid afterSelectionChange返回值

时间:2013-08-08 05:39:41

标签: angularjs ng-grid

使用ng-grid ???

可以使用afterSelectionChange返回值

我该怎样才能完成它?我想获得$ scope.programEdit值,

setPagingData函数设置视图上显示的数据,

getPagedDataAsync函数用$ resource

获取值 有谁的想法?

请帮助

$scope.setPagingData = function(data, page, pageSize, type){
    var array = [];
    for(var key in data){
      if(!data.hasOwnProperty(key)){
        continue;
      }
        array.push(key, data[key])
    }
    if(type == 0){
      var a = array.slice(1,4);
      $scope.myData = a[0];
    }else{
      var a = array.slice(1);
      $scope.myData = a;
    }

    $scope.totalServerItems = data.length;
    if (!$scope.$$phase) {
        $scope.$apply();
    }
    return $scope.myData
};


$scope.getPagedDataAsync = function (pageSize, page, searchText, type) {
    setTimeout(function () {
        var data;
          programService.query({
             page: page
          }, function (result) {
            data = {
              'program': result
            };
            $scope.setPagingData(data,page,pageSize,0)
            return data
          });
    }, 100);

};

$scope.gridOptions = {
    data: 'myData',
    enablePaging: true,
    showFooter: true,
    totalServerItems:'totalServerItems',
    pagingOptions: $scope.pagingOptions,
    filterOptions: $scope.filterOptions,
    selectedItems: $scope.mySelections,
    multiSelect: false,
    afterSelectionChange: function ($routeParams, $location, programService) {
      $scope.program = $scope.mySelections[0];
      var id = $scope.mySelections[0].programId;
      if ($scope.mySelections[0].programId) {
        $scope.programEdit = {
          'program': programService.get({
            page: 1, 
            id: $scope.mySelections[0].programId
          })};
      }


    }
};

我想让它在编辑html上显示

<form ng-submit="save()">
 <input type="hidden" ng-model="programEdit.programId"/>
 <dl> 
  <dt>Program Name</dt>
   <dd><input name="programName" type="text" ng-model="programEdit.programName"/></dd>
  </dl>
  <div class="form-actions">
   <button type="submit">Save</button>
  </div>
</form>

1 个答案:

答案 0 :(得分:1)

$scope.programEdit应该包含programIdprogramName(类似于$scope.programEdit = {programId: 11, programName: 'Hello'},但您要做的是将programService.get设置为名为program的属性。

你应该做什么,假设programService.get是一个promise,并且它返回一个包含数据的JSON对象,那么你应该这样做:

programService.get({ page: 1, id: $scope.mySelections[0].programId }).success(function(data) {
  $scope.programEdit = {programName: data.programName, programId: data.programId};
});