AngularJS& xeditable $ http.post不更新范围返回数据

时间:2014-10-29 16:51:13

标签: php angularjs

我正在努力实现这一目标:http://jsfiddle.net/NfPcH/3951/

但是,更新数据库会增加复杂性。所有工作都与“添加”功能分开。我改变了这个:

// add user
$scope.addUser = function() {
    $scope.inserted = {
        id: $scope.users.length + 1,
        name: '',
        status: null,
        group: null
    };
    $scope.users.push($scope.inserted);
};

进入这个:

    $scope.addRow = function() {
        $code = Math.floor(Math.random() * (9999 - 1000) + 1000);
        $scope.inserted = {
            id: '',
            code: $code,
            description: '',
            location: ''
        };
        return $http.post('php/add.php', $scope.inserted).
        success(function(response) {
            $scope.inserted = response;
            $scope.parts.push($scope.inserted);
        });
    };

数据被添加到数据库中没有任何问题,但是,虽然表单出现,但它不包含id(自动递增的PK)&码。它需要这样做(当然是id),这样当点击'save'按钮时,'edit.php'页面知道要更改哪一行。

任何人都可以告诉我为什么我的$http.post().success没有返回数据?我认为这是问题所在。

1 个答案:

答案 0 :(得分:0)

排序!谢谢你们的帮助,我不知道你们中的一方或双方是否愿意发表答案,以便获得应有的荣誉?当他说物体被包裹时,杰德很开心。它在一个阵列里面。我只是将代码更改为:

$scope.addRow = function() {
$code = Math.floor(Math.random() * (9999 - 1000) + 1000);
    $scope.inserted = { 
        id: '99',
        code: $code,
        description: '',
        location: '' 
    };
return $http.post('php/add.php', $scope.inserted).
    success(function(response) {
        $scope.inserted = response[0];
        $scope.parts.push($scope.inserted);
    });
};

请注意,

$scope.inserted = response[0];

让一切变得与众不同!

相关问题