使用 Parse 和 Angular Js

Working with Parse and Angular Js

我正在尝试根据在文本字段中输入的用户的 objectID 从解析中检索信息。我正在使用 angular 数据绑定,但它似乎运行良好。 下面是显示的结果:

下面是html代码:

<!DOCTYPE html>
<html>
<head>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
  <script src="angular.js"></script>

    <script src="js/functions.js"></script>




</head>
<body ng-app="AuthApp">
    <div ng-controller="MyCntrl">
         userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
            <div>{{addresss}}</div>
    </div>
    </body>
</html>

下面是 js/functions.js 的 javascript :

Parse.initialize("id", "id");


var module = angular.module("AuthApp", []);

module.controller("MyCntrl", function($scope){

$scope.userIdChanged = function () {
    // now access $scope.userId here
    var query = new Parse.Query(Parse.User);

    query.get($scope.userId, {
      success: function(userInfo) {
        // The object was retrieved successfully.
        var address = userInfo.get("Address");
        $scope.address = 'addresss: ' + address;
      },
      error: function(object, error) {
        // The object was not retrieved successfully.
        // error is a Parse.Error with an error code and message.
      }
    }
  };

});

更新:

更新二: 我的控制台错误已被删除,但它似乎无法正常工作,因此这是更新后的代码:

<!DOCTYPE html>
<html>
<head>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>

  <script src="angular.js"></script>


   <script>
   Parse.initialize("pWG7YizRnwxRjplGT9RSLoHtFItDtvmc2EK0YJAe", "C2qlan3y2PXi6nwVbACGT6fY3CTus8oVEvNo889u");


var module = angular.module("AuthApp", []);
module.controller("MyCntrl", function($scope) {
   $scope.userIdChanged = function () {
       // now access $scope.userId here
       var query = new Parse.Query(Parse.User);

       query.get($scope.userId, {
           success: function(userInfo) {
               // The object was retrieved successfully.
               var address = userInfo.get("Address");
               $scope.address = 'address: ' + address;
           },
           error: function(object, error) {
               // The object was not retrieved successfully.
               // error is a Parse.Error with an error code and message.
           }
       });
   };
});
</script>


</head>
<body ng-app="AuthApp">
    <div ng-controller="MyCntrl">
         userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
            <div>{{address}}</div>
            </div>
    </body>
</html>

控制台的错误消息表明您的 javascript 和右括号不匹配。

尝试修复您的代码:

Parse.initialize("id", "id");

var module = angular.module("AuthApp", []);
module.controller("MyCntrl", function($scope) {
   $scope.userIdChanged = function () {
       // now access $scope.userId here
       var query = new Parse.Query(Parse.User);

       query.get($scope.userId, {
           success: function(userInfo) {
               // The object was retrieved successfully.
               var address = userInfo.get("Address");
               $scope.address = 'addresss: ' + address;
           },
           error: function(object, error) {
               // The object was not retrieved successfully.
               // error is a Parse.Error with an error code and message.
           }
       }); // <!-- HERE you forgot to close the opening parenthesis of the query.get method
   };
});

在您看来:

{{addresss}}

应该是:

{{address}}

因为您正在使用 $scope.address


加载动画创意:

$scope.userIdChanged = function () {
   $scope.loading = true;
   // now access $scope.userId here
   var query = new Parse.Query(Parse.User);

   query.get($scope.userId, {
       success: function(userInfo) {
           // The object was retrieved successfully.
           var address = userInfo.get("Address");
           $scope.address = 'address: ' + address;
           $scope.loading = false;
       },
       error: function(object, error) {
           // The object was not retrieved successfully.
           // error is a Parse.Error with an error code and message.
           $scope.loading = false;
       }
   });
};

并且在视图中:

<div ng-controller="MyCntrl">
     userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
     <div>{{address}}</div>
     <div ng-show="loading">Loading data from the server...</div>
</div>