可编辑表angularjs的问题

时间:2014-04-10 18:28:59

标签: angularjs angularjs-scope

我是使用angularjs的新手,我做了一个表,每行我都可以编辑一条记录,这是我的代码......

       <table ng-table="tableParams" show-filter="true" class="table table-striped">
                <tr ng-repeat="user in $data">
                    <td data-title="'Nombre y Apellido'" width="800" filter="{ 'Nombre_completo': 'text' }">
                        <input class="form-control" type="hidden" ng-model="user.PRS_ID" />
                        <span ng-if="!user.$edit">{{user.PRS_NOMBRES}}</span>
                        <div ng-if="user.$edit"><input class="form-control" type="text" ng-model="user.PRS_NOMBRES" ng-value = "{{user.PRS_NOMBRES}}" ng-click="updateValue1()"/></div>
                    </td>
                    <td data-title="'C.I.'" width="200">
                        <span ng-if="!user.$edit">{{user.PRS_CI}}</span>
                        <div ng-if="user.$edit"><input class="form-control" type="text" ng-model="user.PRS_CI" /></div>
                    </td>
                    <td data-title="'Acción'" width="450">
                        <button ng-if="!user.$edit" class="btn btn-default btn-xs glyphicon glyphicon-pencil" style="background-color:#EDE197" ng-click="user.$edit = true">Editar</button>
                        <button ng-if="user.$edit" type="submit" class="btn btn-primary btn-xs glyphicon glyphicon-floppy-disk" ng-click="user.$edit = false; doUpdatePers(user)">Guardar</button>
                        <a class="btn btn-default btn-xs glyphicon glyphicon-trash" style="background-color:#D8D8D8" >Eliminar</a>
                    </td>
                </tr>
            </table> 

我的文件js是:

    var app = angular.module('main', ['ngTable']).
    controller('DemoCtrl', function($scope, $filter, ngTableParams, $sce, $http) {
        $scope.doUpdatePers = function(user) {
                $http({
                    method: 'POST', 
                    url: '../servicios/PersonalAdm.php',
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    data: { 
                            'nombres': $scope.user.PRS_NOMBRES, 
                            'option': "UPD",
                         },

                    }).
                    success(function(data, status) {
                        $scope.data = data;
                        if(data == 'FALSE'){
                            $scope.mensaje = 'todo bien';
                        } else {
                            $scope.mensaje = 'todo mal';
                        }
                    }).
                    error(function(data, status) {
                        $scope.data = data || "FALSE";
                        $scope.status = status;  
                        $scope.mensaje = 'Ha pasado algo inesperado';
                    });
        } 
            //para buscar en la tabla
            $http({
                    method: 'POST',
                    url: '../servicios/PersonalAdm.php',
                    data: {'option': 'LST'},
                }).
            success(function(data){
            $scope.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 6,          // count per page
                filter: {
                Nombre_completo: 'A'       // initial filter
                } 
            }, {
                total: data.length, // length of data
                getData: function($defer, params) {
                    var orderedData = params.filter() ?
                    $filter('filter')(data, params.filter()) :
                    data; 
                    //$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));

                    $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
                    params.total(orderedData.length); // set total for recalc pagination
                    $defer.resolve($scope.users); 
                }
        });
    });

}); 我的问题是我无法获取要发送给我的服务的值,这就是我怎么做$ scope.user.PRS_NOMBRES但是没有工作我想更新记录,我希望你能帮忙我...

0 个答案:

没有答案