Java脚本 - 使用parse.com查询具有角NG-重复脚本、有角、Java、parse

2023-09-13 04:24:13 作者:焚烧的香烟i

我把从parse.com angd get和2的对象数组的查询。现在我想用户NG-reapet('手机手机的),所以我需要将其转换为JSON。我没有suucess做。出于某种原因,它不看到的结果作为一个JSON。

I make a query from parse.com angd get and array of 2 object. Now I want to user ng-reapet('phone in phones') , so I need to convert it to json. I didn't suucess to do it. for some reason, it doesnt see the result as a json.

  var Project = Parse.Object.extend("Project");
  var query = new Parse.Query(Project);
  query.find({
      success: function (results) {
          var allProjects = [];
          for (var i = 0; i < results.length; i++) {
              allProjects.push(results[i].toJSON());
          }
          $scope.phones = allProjects;
          //i also tried this :               $scope.phones = JSON.stringify(allProjects);
      },
      error: function (error) {
          alert("Error: " + error.code + " " + error.message);
      }
  });

感谢

推荐答案

不要在你的角度code使用不用彷徨功能上的解析,它不工作的多了,再加上它不是一个好主意,改变你的角度code,因为你的对象三级嵌套的,需要一个get方法。

Do not use .get function on Parse in you angular code, its not working any more, plus its not a good idea to change your angular code because your object is three level nested and need a get method.

正确的方法是延长对象,然后将值映射回给你的那个类需要的任何物品。然后你就可以在绑定到正常NG-重复而不改变你的HTML code专门为解析。

The proper way is to extend the object and then map the values back to whatever items you need in that class. Then you can bind in normally to ng-repeat without changing your html code specifically for Parse.

var Game = Parse.Object.extend("Game"); 
var query = new Parse.Query(Game);
query.find({
success: function(results) {
  $scope.$apply(function() {
  $scope.games = results.map(function(obj) {
    return {points: obj.get("points"), gameDate: obj.get("gameDate"),  parseObject: obj};
  });
});
},

error: function(error) {
  console.log(error);
}