我在angular.js应用程序中使用数据表。在这个更新之后,我需要在不刷新整个页面的情况下显示更新结果。只需要用新值刷新和更新表。请帮帮忙。
这是我的Controller.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>发布于 2016-01-20 16:19:52
您可以尝试此解决方案:
$route.reload();
$state.reload();
抱歉,如果我误解了你的情况。
发布于 2016-01-20 16:39:45
请在更新数据后尝试添加$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;
});我很难理解你所做的事情。如果有帮助,请告诉我。
https://stackoverflow.com/questions/34893988
复制相似问题