javascript - AngularJS ng-repeat for XML attributes -


working first angularjs project , ran issue. using xml, converted json x2js.

i want display student names: "ed frank jimmy sally"

my current code outputs "ed jimmy" because accessing student[0]._name. how can cycle through name attributes using ng-repeat?

xml

<school>     <teacher name="williams">         <student name="ed"/>         <student name="frank"/>     </teacher>     <teacher name="ramos">         <student name="jimmy"/>         <student name="sally"/>     </teacher> </school>  

json

{     "school": {         "__cnt": 5,         "teacher": [             {                 "__cnt": 6,                 "student": [                     {                         "__cnt": 1,                         "_name": "ed"                     },                     {                         "__cnt": 1,                         "_name": "frank"                     }                 ],                 "student_asarray": [                     {                         "__cnt": 1,                         "_name": "ed"                     },                     {                         "__cnt": 1,                         "_name": "frank"                     }                 ],                 "_name": "williams",                 "__text": [                     "\n\t\t\t",                     "\n\t\t\t",                     "\n\t\t"                 ]             },             {                 "__cnt": 6,                 "student": [                     {                         "__cnt": 1,                         "_name": "jimmy"                     },                     {                         "__cnt": 1,                         "_name": "sally"                     }                 ],                 "student_asarray": [                     {                         "__cnt": 1,                         "_name": "jimmy"                     },                     {                         "__cnt": 1,                         "_name": "sally"                     }                 ],                 "_name": "ramos",                 "__text": [                     "\n\t\t\t",                     "\n\t\t\t",                     "\n\t\t"                 ]             }         ],         "teacher_asarray": [             {                 "__cnt": 6,                 "student": [                     {                         "__cnt": 1,                         "_name": "ed"                     },                     {                         "__cnt": 1,                         "_name": "frank"                     }                 ],                 "student_asarray": [                     {                         "__cnt": 1,                         "_name": "ed"                     },                     {                         "__cnt": 1,                         "_name": "frank"                     }                 ],                 "_name": "williams",                 "__text": [                     "\n\t\t\t",                     "\n\t\t\t",                     "\n\t\t"                 ]             },             {                 "__cnt": 6,                 "student": [                     {                         "__cnt": 1,                         "_name": "jimmy"                     },                     {                         "__cnt": 1,                         "_name": "sally"                     }                 ],                 "student_asarray": [                     {                         "__cnt": 1,                         "_name": "jimmy"                     },                     {                         "__cnt": 1,                         "_name": "sally"                     }                 ],                 "_name": "ramos",                 "__text": [                     "\n\t\t\t",                     "\n\t\t\t",                     "\n\t\t"                 ]             }         ],         "__text": [             "\n\t\t",             "\n\t\t",             "\n"         ]     } } 

html

<body ng-app="productsapp">     <div ng-controller="products">         <h2 ng-repeat="product in products ">             {{product.student[0]._name}}         </h2>     </div>     </body> 

js

var productapp = angular.module('productsapp',[]); productapp.factory('productfactory',function($http){     var factory = [];     factory.getproducts = function(){         return $http.get("js/allproducts.xml");     }     return factory; }); productapp.controller('products',function($scope,productfactory){     $scope.products = [];     loadproducts();     function loadproducts(){         productfactory.getproducts().success(function(data){             schools = x2js.xml_str2json(data);             console.log(schools.school.teacher);             $scope.products =schools.school.teacher;         });     } }); 

i had change html this:

<body ng-app="productsapp"> <div ng-controller="products">     <div ng-repeat="product in products">         <div ng-repeat="teacher in product.student " style="color:red;">         {{teacher._name}}         </div>     </div> </div> 

i didn't know how use nesting correctly. everyone!


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -