Angularjs 不更新数据表信息
我有一张班级名单。正如你在第一张图中所看到的,每个班级有不同数量的学生 头等舱->3 二等舱->0 三等舱->1 当我单击“(3)”时,我将变量“sinif”用作$scope.sinif,以便在模式中使用。我用ng repeat在模态中列出$scope.sinif.ogrenciler。当我单击(3)时,列表是正确的。但当我关闭模式并单击(0)时,信息不会更新。同样,当我单击(1)时。我们怎样才能解决这个问题 这是我的第一份名单。单击以下模式后,将打开 模态 这里有个问题。查找信息 这是我的情态Angularjs 不更新数据表信息,angularjs,angularjs-directive,datatables,Angularjs,Angularjs Directive,Datatables,我有一张班级名单。正如你在第一张图中所看到的,每个班级有不同数量的学生 头等舱->3 二等舱->0 三等舱->1 当我单击“(3)”时,我将变量“sinif”用作$scope.sinif,以便在模式中使用。我用ng repeat在模态中列出$scope.sinif.ogrenciler。当我单击(3)时,列表是正确的。但当我关闭模式并单击(0)时,信息不会更新。同样,当我单击(1)时。我们怎样才能解决这个问题 这是我的第一份名单。单击以下模式后,将打开 模态 这里有个问题。查找信息 这是我
<!-- Modal -->
<div class="modal fade in" id="SinifOgrenci" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel"> {{this.sinif.sinifAdi}} - Öğrencileri </h4>
</div>
<div class="modal-body">
<table datatable-setups ng-if="sinif.ogrenciler" class="table table-bordered table-striped js-dataTable-full-pagination">
<thead>
<tr>
<th class="hidden-xs" style="width: 5%;"></th>
<th class="text-center">Öğrenci Adı Soyadı</th>
<th class="text-center">Yaş</th>
<th class="text-center">Boy</th>
<th class="text-center">Cinsiyet</th>
<!--<th class="text-center">Aktif / Pasif</th>-->
</tr>
</thead>
<tbody>
<tr ng-repeat="ogrenci in sinif.ogrenciler">
<td class="hidden-xs">{{this.ogrenci.id}}</td>
<td class="text-center">{{this.ogrenci.adSoyad}}</td>
<td class="text-center">{{this.ogrenci.yas}}</td>
<td class="text-center">{{this.ogrenci.boy}}</td>
<td class="text-center">{{this.ogrenci.cinsiyet}}</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"> Kapat </button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
dataTables只有在自己负责绘制表时才能更新信息。但您只是使用
ng repeat
呈现内容。dataTables应该如何知道您的$scope
变量发生了什么事情?是的,如果单击count,ng click=“setSinif(sinif)”
调用并$scope.setSinif=function(sinif){$scope.sinif=sinif;}
不知道上面的注释代码应该解决什么:)将复杂的jQuery插件作为数据表与angular混合使用只会导致沮丧和奇怪的行为,例如竞争条件的结果。在反复重新初始化dataTable或让dataTable本身负责渲染之前,您将以各种方式面临此问题。如果没有遇到问题,就无法进行上述设置。另一种方法是使用角度数据表,我使用它来解决所有这些可预测的问题。
angular.module("app")
.directive('datatableSetups', ['$timeout', '$rootScope',
function ($timeout, $rootScope) {
return {
restrict: 'A',
link: function (scope, element) {
$timeout(function () {
element.dataTable({
pagingType: "full_numbers",
columnDefs: [],
pageLength: 10,
lengthMenu: [[5, 10, 15, 20], [5, 10, 15, 20]]
});
});
}
};
}
]);