繁体   English   中英

使用角度数据绑定从Parse检索和显示信息

[英]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

<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>

s

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM