2017-02-10 60 views
0

我正在研究angularjs應用程序。我正在顯示基於用戶輸入值的角度UI網格。我想在UI網格的每一行中顯示單選按鈕,並且默認情況下應該選擇第一行單選按鈕。用戶應該能夠選擇任何一行單選按鈕。請找到代碼demo here無法在網格的每一行顯示單選按鈕

要顯示UI網格,在From文本字段中輸入Atlanta並在To文本字段中輸入Chicago,然後單擊SearchLocations,我無法看到行中的單選按鈕,而是顯示賦值爲true/false的值。任何建議都會非常有幫助。

的html代碼:

<div class="row"> 
     <div class="form-group" ng-controller="citiesCtrl"> 
      <label>From</label> 
      <input type="text" ng-model="places[0]" placeholder="Type Departure City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
     <div class="form-group" ng-controller="citiesCtrl"> 
      <label>To</label> 
      <input type="text" ng-model="places[1]" placeholder="Type Destination City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
    </div> 

    <input type="button" value="SearchLocations" ng-click="submit()"> 

    <div ng-repeat="user in filteredUsers = (users | filter: {name: searchValue} : true)"> 
     <h3>First Grid</h3> 
     <div ui-grid="{ data: user.details }" ng-show="user.show" class="myGrid"></div> 
    </div> 

    <div ng-if="!filteredUsers.length && searched"> 
     No data available 
    </div> 

JS代碼:

angular.module('myApp', ['ngAnimate', 'ui.bootstrap','ngTouch', 'ui.grid', 'ui.grid.edit','ui.grid.selection', 'ui.grid.edit','ui.grid.cellNav']); 
     angular.module('myApp').controller('citiesCtrl',function($scope){ 
      // $scope. places = undefined; 
      $scope.items = ["Atlanta", "Chicago", "NewYork"]; 
      $scope.selectAction = function() { 
       console.log($scope.places1); 

      }; 
     }); 

    /*Controller for searchLocations button*/ 
     angular.module('myApp').controller('searchController', ['$scope', function($scope) { 
      $scope.places = ['', '']; 
      $scope.searchValue = ''; 
      $scope.searched = false; 

      $scope.submit = function() { 
       $scope.searched = true; 
       if ($scope.places[0].length > 0 && $scope.places[1].length > 0) { 
        $scope.searchValue = $scope.places[0] + $scope.places[1]; 
       } 
      }; 

      $scope.users = [ 
       {'name' : 'AtlantaChicago', 
        'show' : true, 
        'details' : [ 
         {"Travel Date": "10/10/2014", commute:"Bus", "zip":"1222","isActive" : true}, 
         {"Travel Date": "10/11/2014", commute:"flight","zip":"11562","isActive" : false}] 
       }, 
       {'name' : 'NewYorkChicago', 
        'show' : true, 
        'details': [ 
         {"Travel Date": "3/15/2016", commute:"flight","zip":"666","isActive" : true}, 
         {"Travel Date": "10/12/2016", commute:"flight","zip":"4532","isActive" : false}, 
        ] 
       } 
      ]; 
      $scope.gridOptions = { 
       enableFiltering: true, 
       columnDefs: [ 
        { name: 'Travel Date', width: '5%'}, 
        { name: 'Departurecommute', enableFiltering: false, width: '12%' }, 
        { name:'zip', field: 'getZip()', enableCellEdit:false}, 
        { name:'isActive', width:300, field: 'radio', cellTemplate: '<div ng-init="releaseAction=0"><input name="Release{{grid.renderContainers.body.visibleRowCache.indexOf(row)}}" type="radio" ng-model="releaseAction" ng-value="1" style="width:20px"></div>'} 

       ], 
       rowHeight: 20, 
       enableHorizontalScrollbar:2 

      }; 
     }]); 

回答