我正在使用 ng-table ,表中的每一行都有ng-init,它调用一个方法给它的控制器。在选择 Shift 下拉表时,将填充数据,并使用ng-init指令将每行调用 getAlltemplates()。当我更改 Shift 选项时,表格数据会被填充,但 getAlltemplates()将不会被调用。
我用Google搜索了这个问题,但我没有找到任何有用的信息。请帮我解决这个问题。
HTML Code Snippet:
<div class="filter-box box-shift">
<span class="filter-label">Shift</span>
<div id="checkOutShift" ng-dropdown-multiselect="" options="shifts" selected-model="checkOutShiftSelected" class="selectautocomplete" extra-settings="shiftSettings" events="{onItemSelect:checkOutShiftChange}"></div>
</div>
<table ng-table="checkoutTable" show-filter="true" class="table table-striped">
<tr ng-repeat="checkout in $data">
<td data-title="'No'">
{{ ((checkoutTable.page() - 1) * checkoutTable.count()) + ($index+1) }}
</td>
<td data-title="'Template'">
<div>
<select ng-attr-id="{{'templates'+((checkoutTable.page() - 1) * checkoutTable.count()) + ($index+1)}}" ng-model="templateSelected[((checkoutTable.page() - 1) * checkoutTable.count()) + ($index+1)]" ng-options="checkoutTemplate.nameEn for checkoutTemplate in equipTemps[(((checkoutTable.page() - 1) * checkoutTable.count()) + ($index+1))]">
<option value="">Select</option>
</select>
</div>
</td>
<td data-title="'Operator'">
<div>
<select ng-attr-id="{{'operators'+((checkoutTable.page() - 1) * checkoutTable.count()) + ($index+1)}}" ng-model="operatorSelected[((checkoutTable.page() - 1) * checkoutTable.count()) + ($index+1)]" ng-options="operator.firstName+' '+operator.lastName for operator in operators">
<option value="">Select</option>
</select>
</div>
</td>
</tr>
</table>
AngularJs Code Snippet:
$scope.checkOutShiftChange = function(){
//...
$scope.displayCheckOut();
};
$scope.displayCheckOut = function() {
//hit the http service and save the response to $scope.checkoutlist
$scope.checkoutTable = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
filter: {
},
sorting: {
}
}, {
total: $scope.checkoutlist.length, // length of data
getData: function($defer, params) {
// use build-in angular filter
var filteredData = params.filter() ? $filter('filter')($scope.checkoutlist, params.filter()) : $scope.checkoutlist;
var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : $scope.checkoutlist;
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
};
$scope.getAlltemplates=function(equipType, index, fkTemplateId){
//method to get the list of templates from a service using equipType, index, fkTemplateId
};