在解析中检索信息

retrieving information in parse

我能够从 Parse 中的当前用户检索信息,但是,我希望能够从当前用户以外的任何人检索信息。

例如,这是我检索和显示有关当前用户的信息的方式:

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

angular.module('AuthApp', [])
.run(['$rootScope', function($scope) {
  $scope.currentUser = Parse.User.current();

比 html 我这样称呼它:

{{currentUser.get('username')}} 

我不想从当前用户那里提取信息,而是从他们 objectID.Hence 确定的另一个用户那里提取信息,我的问题是如何提取 objectid 为 17845

的用户的信息

更新:

<script type="text/javascript">
$(document).ready(function() {

  // ***************************************************
  // NOTE: Replace the following your own keys
  // ***************************************************
  var userID = document.getElementById("txtUserID").value;

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


var userInfo = Parse.Object.extend("User");
var query = new Parse.Query(userInfo);
query.get(userID, {
  success: function(userInfo) {
    // The object was retrieved successfully.
    var score = userInfo.get("Address");


 var message = 'Address: ' + score;
        document.getElementById('address').innerHTML = message;
  },
  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-show="currentUser">

  <input name="txtUserIDName" id="txtUserID"  type="text" value="Please enter your user ID">



</div>

  </div>
</body>
</html>

更新二:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
<!--======================================================================-->
<!--Custom website css file is linked here-->
<link href="css/style1.css" rel="stylesheet">
<!--Font Awesome CSS link-->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!--=================================================-->
<!--Javascript file linked here-->
<script src="js/bootstrap.min.js"></script>
<script src="js/personal.js"></script>
    <script src="js/functions.js"></script>

<meta charset=utf-8 />
<title>Admin Panel</title>

<script type="text/javascript">
$(document).ready(function() {

  // ***************************************************
  // NOTE: Replace the following your own keys
  // ***************************************************

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


app.controller('MainCtrl', function($scope) {
  $scope.userIdChanged = function () {
    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-Controller="MainCtrl">
    userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
    <div>{{address}}</div>
</body>
</html>
var query = new Parse.Query(Parse.User);

query.get('17845', {
  success: function(userInfo) {
    // The object was retrieved successfully.       
  },
  error: function(object, error) {
    // The object was not retrieved successfully.
    // error is a Parse.Error with an error code and message.
  }
});

更新答案:

而不是使用 dom 操作 javascript 例如 document.getElementById 和 jquery $(document).ready,你应该使用 angular 数据绑定。无需使用 var userInfo = Parse.Object.extend("User");,因为 Parse.User.

中已提供
app.controller('MainCtrl', function($scope) {
  $scope.userIdChanged = function () {
    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.
      }
    });
  };
});

Html:

我在这里使用 ng-blur,它会在值更改且文本框失去焦点时调用作用域上的 userIdChanged 方法。您也可以有一个按钮并使用 ng-click。

<body ng-Controller="MainCtrl">
    userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
    <div>{{address}}</div>
</body>