【问题标题】:How to display the query results from parse.com in table format using angularjs如何使用angularjs以表格格式显示来自parse.com的查询结果
【发布时间】:2015-03-04 16:25:49
【问题描述】:
     /*student.html*/
     <!DOCTYPE html>
     <html ng-app="">
    <head>
  <link rel="stylesheet"     href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">


  <link rel="stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">



<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js">    </script>
 <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>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
 <script src= "students.js"></script>
</head>

<body >
  <div class="container" ng-controller="userController">

  <h3>Students</h3>

   <table class="table table-striped">
  <thead><tr>
<th>Edit</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr></thead>
  <tbody><tr ng-repeat="user in users">
  <td>
  <button class="btn" ng-click="editUser(user.id)">
  <span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;Edit
  </button>
</td>
<td>{{ user.firstname}}</td>
<td>{{ user.lastname }}</td>
<td>{{ user.age }}</td>
   </tr></tbody>
 </table>

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

请帮助我,我是 angularjs 的新手,也是第一次使用 parse。我在 angularjs 中使用 ng-repeat 显示查询结果(这是一个对象数组)时遇到了困难。任何遇到过同样情况的人问题,请贡献你的答案..

/*stduents.js*/
function userController($scope) {
var users=[];
Parse.initialize("parseid", "jskey");//parseid and jskey are given in my parse.com account
var student=Parse.Object.extend("student");//student is a class in parse.com
var query=new Parse.Query(student);
query.equalTo("userid",Parse.User.current());
query.find({
success:function(results) {
alert("success");
for(var i=0;i<results.length;i++)
{
 var object= results[i];
users.push({'firstname':object.get('firstname') , 'lastname':object.get('lastname') ,'age':object.get('age')});

}

},
 error:function(error) {
 alert("error:"+ error.code +" "+error.message);
 }
});

【问题讨论】:

标签: javascript angularjs html twitter-bootstrap-3 parse-platform


【解决方案1】:

ng-repeat的简单用法:

样本数组

var arr = [
    {id: 1},
    {id: 2},
    {id: 3}
]

示例使用

<span ng-repeat="obj in arr">{{obj.id}}</span>

这会给你

123

Fiddle

我建议阅读Docs

【讨论】:

  • 是的,我知道上面的那个,但是 parse.com 查询结果返回的数组是不同的(它返回的对象数组“不是你所采用的简单数组”)..
  • 我的问题是如何将“users”数组(在我的代码中)更改为简单数组“arr”的格式(在您的代码中)??
  • 给我们你的 JSON 样本
  • var users=[{firstname:'sharath' ,lastname:'reddy' ,age:22}];
  • 它应该是什么样子?
【解决方案2】:

只需将 student.js 中的第三行更正为 $scope.users=[];

【讨论】:

  • 这没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时评论自己的帖子,一旦您有足够的reputation,您就可以comment on any post
  • 嗨@callmekatootie,实际上作者是我的朋友,我看到他的代码,我发现了错误,根据他的代码,上面指定的答案使他的代码工作
猜你喜欢
  • 2019-08-09
  • 1970-01-01
  • 2017-01-07
  • 2010-09-30
  • 2012-08-15
  • 2015-01-19
  • 2021-09-01
  • 1970-01-01
相关资源
最近更新 更多