【问题标题】:Angular checkbox not saving its state between page navigationAngular 复选框未在页面导航之间保存其状态
【发布时间】:2016-11-26 01:56:44
【问题描述】:

我正在使用 Angular Table,它使用 ng-repeat 显示来自 MySQL 的记录。 最后一列是复选框列。 问题是在页面之间导航(分页)时,复选框的状态是持久加载的。 如何保持页面之间的状态(如果我选中/取消选中某个项目)?

<tr ng-repeat="data in filtered = (list | filter:search | 
filter:{manufacturer:by_manufac} | 
filter:{errorStatus:by_errorStatus} | 
orderBy : predicate :reverse) | 
startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">

<td>
    <input type="checkbox" name="checkedin" ng-model='checkedin' 
    ng-change='processForm(data)' ng-checked="data.Locked==1"/>
</td>
</tr>

在控制器中:

$scope.processForm = function(checkedindata) {
      $http.post('ajax/setItems.php', { data : checkedindata })
    };

【问题讨论】:

    标签: angularjs checkbox ngtable angularjs-ng-checked


    【解决方案1】:

    对于那些对解决方案感兴趣的人: 在控制器中,只需像这样更新 $scope 的值:

       $scope.processForm = function(post_data) {
            for(i=0; i<$scope.filtered.length; i++) {
              if($scope.filtered[i]['productID'] == post_data['productID']){
                  $http.post('ajax/setItems.php', { id : post_data['productID'], operation: !post_data['Locked'] })
                  $scope.filtered[i]['Locked'] = !$scope.filtered[i]['Locked'];
                  i=$scope.filtered.length;
              }
            }
        };
    

    【讨论】:

    • 这里的productID是什么?
    • 是传给控制器的json对象的名字。然后你可以在你的 PHP 或任何其他后端使用它来提取它的值。
    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多