在角度.js中编辑后立即刷新数据表
Refresh datatable immediately after edit in angular.js
我在我的angular.js应用程序中使用数据表。在更新后,我需要在不刷新整个页面的情况下显示更新结果。只需刷新表并使用新值进行更新。请帮忙。
这是我的控制者.js
$scope.updateInternship = function() {
$("#internshipEdit").modal('hide');
internshipService.updateInternship(
$scope.internship,
function(data) {
$rootScope.loggedInUser = data;
$scope.internship = data;
$growl.box(
'Hello!',
'Your details have been updated.',
{
class : 'success',
sticky : false,
timeout : 5000
}
).open();
}
);
}
这是显示表格的 html 页面。
<table datatable="ng" dt-options="dtOptions" cellspacing="0" width="100%" class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Category</th>
<th>Status</th>
<th>Created date</th>
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Title</th>
<th>Category</th>
<th>Status</th>
<th>Created date</th>
<th>Action</th>
</tr>
</tfoot>
<tbody>
<tr ng-repeat="internship in allinternships">
<td><span>{{$index+1}}</span></td>
<td><span>{{internship.title}}</span></td>
<td><span>{{internship.category.name}}</span></td>
<td><span>{{internship.status}}</span></td>
<td><span>{{internship.appliedDate | date:'d MMMM yyyy'}}</span></td>
<td>
<button class="btn btn-default btn-sm" data-title="Hold" data-toggle="modal" ng-click="hold(internship.id)">
<i class="fa fa-pause"></i>
</button>
<a href="javascript:;" class="btn btn-default btn-sm" data-title="Edit" data-toggle="modal" ng-click="update(internship.id)" >
<i class="icon bb-edit"></i>
</a>
<button class="btn btn-default btn-sm" data-title="View" data-toggle="modal" ng-click="deleteinternship(internship.id,$index)">
<i class="icon bb-trash"></i>
</button>
<button class="btn btn-default btn-sm" data-title="View" data-toggle="modal" ng-click="viewInternship(internship.id)">
<i class="icon bb-view"></i>
</button>
</td>
</tr>
</tbody>
</table>
你可以试试这个解决方案:
-
如果您使用的是路由提供程序,则可以使用
$route.reload();
-
如果您使用的是$state提供程序,则可以使用
$state.reload();
对不起,如果我误解了你的情况。
尝试在更新数据后添加$scope.$apply();
。
否则请尝试:
$scope.$watch(function() {
// Here you should return the value that changes
return $scope.internship;
}, function() {
// You arrive here if the returned element before has changed
$scope.internship = data;
});
我很难理解你在做什么的行为。让我知道它是否有帮助。
相关文章:
- 数据表刷新不起作用
- 如何刷新数据表列数据
- 数据表上的行计数不会刷新
- 允许在表刷新后键入数据表搜索按钮
- 数据库更新后刷新数据表
- 如何在后退/前进或刷新后保留数据表中的筛选器
- 数据表无限 + 自动数据刷新
- 从数据表中删除行而不刷新整个页面
- 数据表每 30 秒自动刷新一次不起作用
- 主干:更改集合后刷新数据表
- 谷歌折线图,刷新数据表
- 在角度.js中编辑后立即刷新数据表
- 刷新数据表时出错-无法重新初始化数据表
- 勾选复选框全选,并刷新数据表
- 如何在调用页事件后刷新数据表
- 如何从ajax/错误回调中刷新数据表
- 如何刷新数据表列表
- 使用draw()、ajax、分页刷新数据表
- Ajax发布到springmvc控制器,用于刷新数据表
- 标签更改后,jsf中无法刷新数据表