2

我希望在文本框中获取要编辑的值,即第一个文本框将为空,然后当用户单击编辑链接时,应在文本框中填写值。用户可以更改值,单击保存按钮,新值将被更新。以下是代码:

html代码:保存

控制器:

$scope.fetch = function(id) {
            var elem = angular.element($element);
            var dt = $(elem).serialize();
            dt = dt+"&id="+id;
            dt = dt+"&action=fetch";
            alert(dt);
            console.log($(elem).serialize());
            $http({
                method: 'POST',
                url: 'php/products.php',
                data: dt,
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            }).success(function(data, status) {
                //~ $scope.status = status;
                //~ $scope.data = data;
                $scope.rs = data;
                console.log($scope.rs); // Show result from server in our <pre></pre> element
            }).error(function(data, status) {
                $scope.data = data || "Request failed";
                $scope.status = status;
            });
        };

产品.php:

if($action == 'fetch') {
$query = '
SELECT 
    * 
FROM 
    product
WHERE 
    `product_id` ="' . $_POST['id'] . '"
';
$result = mysql_query($query) OR die(mysql_error()); 
$data = array();
$row = mysql_fetch_assoc($result); 
echo json_encode($row);
//print_r($row);

}

此代码不起作用-当用户单击任何用户的编辑链接时,文本框将填充值对象对象。如果 ti 打印该值,则它会被打印,但是当我尝试将其分配给文本框时,它会被 Object 对象填充。我哪里错了?我该如何解决这个问题?

4

2 回答 2

0

如果您使用 Angular,请不要再使用 jQuery 来获取/设置字段。

<input type="text" ng-model="field1">

控制器:

//set
$scope.field1 = obj.field1;

//get
var f1 = $scope.field1;
于 2012-09-18T17:29:29.740 回答
0

angular.fromJson收到回复时忘记使用该功能

.success(function(json, status) {
                data=angular.fromJson(json);
                //~ $scope.status = status;
                //~ $scope.data = data;
                $scope.rs = data;
                console.log($scope.rs); // Show result from server in our <pre></pre> element
            })

您可能想看看AngularPHP并节省一些时间,

于 2014-01-09T11:32:31.530 回答