[英]Parse retrieve a particular user information and display it (Javascript)
[英]Using angular databind to retrieve and display information from Parse
我正在使用角度數據綁定來從Parse檢索和顯示信息。 特別是,我想要的是在query.get中使用用戶在文本字段中輸入的ObjectID來檢索該特定用戶的各種信息。 這似乎不起作用,我想知道代碼中是否有錯字。
以下是Javascript代碼:
Parse.initialize("ID", "ID");
angular.module('AuthApp', [])
.run(['$rootScope', function($scope) {
$scope.scenario = 'Sign up';
$scope.currentUser = Parse.User.current();
$scope.signUp = function(form) {
var user = new Parse.User();
user.set("password", form.password);
user.set("username", form.username);
user.signUp(null, {
success: function(user) {
window.location = 'myprofile.php'
},
error: function(user, error) {
alert("Unable to sign up: " + error.code + " " + error.message);
}
});
};
$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.
}
});
};
特別是,這是受影響的部分:
$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部分:
<!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>
</head>
<body ng-app="AuthApp">
<div ng-show="currentUser">
userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
<div>{{addresss}}</div>
</div>
</body>
</html>
任何幫助將不勝感激。
更新:下面是顯示的結果:
以下是html代碼:
<!DOCTYPE html>
<html>
<head>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
<script src="js/functions.js"></script>
<script src="angular.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>
以下是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.
}
}
};
});
將控制器與模塊關聯,以在scope方法中訪問$ scope值。 示例代碼如下:
<html>
<head>
...
</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>
var module = angular.module("AuthApp", []);
module.controller("MyCntrl", function($scope){
$scope.userIdChanged = function () {
// now access $scope.userId here
};
});
試試這個,對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.