0

可以使用 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>
4

1 回答 1

1

$scope.programEdit应该包含programIdand programName(类似于$scope.programEdit = {programId: 11, programName: 'Hello'}但你所做的是设置programService.get一个名为 program.properties 的属性。

你应该做什么,假设 programService.get 是一个承诺,并且它返回一个带有数据的 JSON 对象,那么你应该做这样的事情:

programService.get({ page: 1, id: $scope.mySelections[0].programId }).success(function(data) {
  $scope.programEdit = {programName: data.programName, programId: data.programId};
});
于 2013-08-08T06:54:01.597 回答