2015-03-03 80 views
-2
 /*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..anyone NG重复谁曾碰到过同样的问题的对象),请贡献你的答案..如何使用angularjs以表格格式显示来自parse.com的查询结果

/*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); 
} 
}); 
+1

请添加足够的代码和标记片段来演示您尝试失败的方法。 – mccainz 2015-03-03 13:37:56

+0

hi @mccainz我已添加代码片段。请检查一下。 – Sharathreddy 2015-03-04 01:40:30

+0

http://plnkr.co/edit/sogtgtDrz21pd9p2yXhj?p=preview – Sharathreddy 2015-03-04 12:42:57

回答

2

ng-repeat简单的用法:

样品阵列

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

使用范例

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

这会给你

123 

Fiddle

我建议您阅读Docs

+0

是的,我知道上面的一个,但parse.com返回的数组查询结果是不同的(它返回对象数组“不是一个简单的数组,你有采取“).. – Sharathreddy 2015-03-03 17:38:15

+0

我的问题是如何将”用户“数组(在我的代码中)变成简单数组”arr“(在你的代码中)的格式? – Sharathreddy 2015-03-04 02:13:59

+0

给我们一个* JSON * – DonJuwe 2015-03-04 08:49:18

-1

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

+1

这并不是提供了一个问题的答案。要批评或要求作者澄清,在他们的帖子下留下评论 - 你总是可以评论你自己的帖子,一旦你有足够的[声誉](http://stackoverflow.com/help/whats-reputation),你会能够[评论任何帖子](http://stackoverflow.com/help/privileges/comment)。 – callmekatootie 2015-03-04 09:24:44

+0

嗨@callmekatootie,其实作者是我的朋友,我看到他的代码,我发现错误,根据他的代码,上面指定的答案使他的代码工作 – CypherPheonix 2015-07-15 20:44:17