2017-02-13 23 views
0

我使用UI-Grid來顯示我的角度app中的出勤數據。我已經使用了三個選項來存儲在單獨的數組中。angular-ui-grid中的Celltemplate無法正常工作

$scope.gridOptions.data.attendance=[{'persent'},{'absent'},{'leave'}]; 

和學生的數量顯示爲:

$scope.gridOptions.data=students;//from ajax request 

現在我想展示在出席列下拉。

enter image description here

我也想顯示persent作爲選擇的默認option.so我用NG-選項celltemplate和代碼是這樣的:

$scope.gridOptions = { 
     columnDefs: [ 
      { 
       name: "stdattendance", 
       displayName: "Attendance", 
       width: '20%', 
       cellClass: 'grid-align', 
       cellTemplate:'<select ng-model="row.entity.stdattendnce" ng-init="row.entity.stdattendnce=row.entity.attendance[0]" 
       ng-options="s as s.description for s in row.entity.attendance track by s.id"></select>' 
       }] 

我面臨的問題是:

1-默認選項persent在沒有滾動顯示的網格中被選中,而在網格的下半部分未被選中。

2 - 當我選擇一個選項時,它也會在一些下部網格中隨機選擇。

我無法弄清楚這種奇怪的行爲,任何人都可以幫忙嗎?

回答

0

NG-的init =「row.entity.stdattendnce = row.entity.attendance [0] 是導致問題的錯字 這將有助於看到這個在plunkr 這是角plunkr:?https://plnkr.co/edit/RJZXudKJKBVIKhoxjXW0

<body ng-app="defaultValueSelect"> 
    <div ng-controller="ExampleController"> 
    <form name="myForm"> 
    <label for="mySelect">Make a choice:</label> 
    <select name="mySelect" id="mySelect" 
     ng-options="option.name for option in data.availableOptions track by option.id" 
     ng-model="data.selectedOption"></select> 
    </form> 
    <hr> 
    <tt>option = {{data.selectedOption}}</tt><br/> 
</div> 
</body> 

注意,所選的選項在使用範圍NG-模型設定,並確定在模板中。

+0

我的問題是在電網使用這種有問題。 –