AngularJS ng-repeat groupby not working

时间:2013-12-11 17:38:37

标签: json angularjs group-by ng-repeat

我有一个XML文件

<Data>
 <Student>
   <ID>121</ID>
   <Surname>STEVE</Surname>
   <Forename>SMITH</Forename>
   <Year>2003</Year>
   <Attendance>76</Attendance>
   <CGPA>4.2</CGPA>
 </Student>
 <Student>
   <ID>121</ID>
   <Surname>STEVE</Surname>
   <Forename>SMITH</Forename>
   <Year>2004</Year>
   <Attendance>87</Attendance>
   <CGPA>4.3</CGPA>
 </Student>
 <Student>
   <ID>122</ID>
   <Surname>DAVID</Surname>
   <Forename>JHONSON</Forename>
   <Year>2007</Year>
   <Attendance>82</Attendance>
   <CGPA>4.5</CGPA>
 </Student>
 <Student>
   <ID>122</ID>
   <Surname>DAVID</Surname>
   <Forename>JHONSON</Forename>
   <Year>2008</Year>
   <Attendance>68</Attendance>
   <CGPA>3.2</CGPA>
 </Student>
 </Data>

我已经将它转换为JSON,并且从控制器我使用ng-repeat来显示数据。 我的预期输出是

121 STEVE SMITH
2003 76 4.2
2004 87 4.3
122 DAVID JHONSON
2007 82 4.5
2008 68 3.2

我尝试了许多但是无法做到,因为网上的例子都不像我的。以下是我目前正在尝试的内容

  <div ng-repeat="student in dataSet" class="resultwrapper">
  <h2>{{studentstudent.ID}} {{student.Surname}} {{student.Forename}}</h2>
    <div ng-repeat="Year in student">
      {{student.Year}}
    </div>
    <div ng-repeat="Attendance in student">
      {{student.Attendance}}
    </div>
    <div ng-repeat="CGPA in student">
      {{student.CGPA}}
    </div>
</div>

用于将XML转换为JSON的代码。我正在接受一般xml2json.js的帮助

var AppController = function($scope,DataSource) {

var SOURCE_FILE = "data.xml";

xmlTransform = function(data) {
    console.log("transform data");
    var x2js = new X2JS();
    var json = x2js.xml_str2json( data );
    return json.Data.Student;
};

setData = function(data) {
    $scope.dataSet = data;
};

DataSource.get(SOURCE_FILE,setData,xmlTransform);

};

请指教。非常感谢.. 明海

0 个答案:

没有答案