javascript - Angular.JS Sub-Array access [& parsing a key] -


it's first time trying build angular , , find myself not able retrieve json data.

the data retrieve sql database in json form passed template angular route :

.when('/tasks/:taskid',{     templateurl: 'template/task_data_template.html',     controller:"showtaskdata",     controlleras: 'std' }) 

the showtaskdata defined follow :

angular.module('moondive').controller('showtaskdata',function($http,$routeparams){  var store = this;   store.tasks= [];  json_url = 'api/tasks_data.php?taskid=' + $routeparams.taskid;   $http.get(json_url).success(function(data){     store.tasks = data;  })}); 

my data have structure : data structure

this accessible template html :

{{std.tasks[1]}} 

which return data in "json" way :

{     "actionid": "1",     "taskref": "1",     "ast1_1": "",     "ast2_1": "start eva watch\nopen           hatch\nassist cdr",     "ast3_1": "",     "ast1_2": "egress cabin lm porch\nreceive &      jetttison bag\nreceive etb/lec",     "ast2_2": "deploy cdr plss antenna\nhand jettison      bag cdr\nhand etb/lec cdr",     "ast3_2": "",     "ast1_3": "descend lander top rung\nunlock , deploy mesa\nlower etb on lec",     "ast2_3": "tape recorder -off\nverify voice signals level , uitlity floo [......]" } 

so far good, final purpose have table 2 column (ast1 , ast2) , x row x task. i'm not sure how begin , i've tried :

<table class="bordered hoverable responsive-table"> <tbody>  <tr ng-repeat="boo in std.tasks[1]"> <td style=" color: blue;" ng-if="$odd"> {{boo}}</td> <td style="color:red" ng-if="$even"> {{boo}}</td> </tr> </tbody> </table> 

well no luck doesn't work @ all, 1 weird thing prevent me understand what's going on displays information in seems random order.

enter image description here

i'd delete rows "1" ; ng-if="boo.nameoftherow" ; here don't have access name ?

so question : how delete unnecessary data? , how can arrange data astr1 , 2 (for columns) , task 1 x (for rows)

thanks lot !

ps : generated code should :

<table>  <thead>     <td> task </td>     <td> astr 1 </td>     <td> astr 2 </td>     <td> astr 3 </td> </thead>  <tbody>  <tr>     <td> 1</td>     <td> {{std.tasks[1].ast1_1}} </td>     <td> {{std.tasks[1].ast2_1}}</td>     <td>{{std.tasks[1].ast3_1}}   </td> </tr> <tr>     <td> 2</td>     <td> {{std.tasks[1].ast1_2}} </td>     <td> {{std.tasks[1].ast2_2}}</td>     <td>{{std.tasks[1].ast3_2}}   </td> </tr>  <tr>     <td> 3</td>     <td> {{std.tasks[1].ast1_3}} </td>     <td> {{std.tasks[1].ast2_3}}</td>     <td>{{std.tasks[1].ast3_3}}   </td> </tr>  .... <tr>     <td> 7</td>     <td> {{std.tasks[1].ast1_7}} </td>     <td> {{std.tasks[1].ast2_7}}</td>     <td>{{std.tasks[1].ast3_7}}   </td> </tr>       </tbody></table> 

thus data should displayed : enter image description here

if std.tasks array of entries, need change ng-repeat ng-repeat="boo in std.tasks".

you should getting json data in array form:

[   {"field":"value", "field2": "value"},   {"field":"value", "field2": "value"},   {"field":"value", "field2": "value"},   ... ] 

ng-repeat want iterate on each of values in array. right now, you've pointed first item in array, it's repeating on each property in object.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -