javascript - nested ng-repeat with dynamic input -


i trying display json response in table using ng-repeat. problem not objects recieved same. of them have date, short message , long message. there ones additional value list, differing in length. list should diplayed underneath long message within own table or list. use alert.slice().reverse() because want newest entries on top. new objects inserted using .push({values}).

<tbody class="altbody" ng-repeat="alerts in alerts.slice().reverse()" ng-class="classname">                      <tr class="altr aldate" >                          <td ng-show="{{alerts.date}}" ><b>{{alerts.date}}:</b></td>                      </tr>                      <tr class="altr alshort "  ng-click="toggledetail($index)">                          <td >{{alerts.s}}</td>                      </tr>                      <tr class="altr " ng-show="activeposition == $index">                            <td class="msgl">{{alerts.l}}                           <!-- 1)  <p ng-show="{{item.list}}"><br><ul><li>previous values:</li> <li ng-repeat="vals in valuelist">{{vals.value}}</li></ul> </p>-->                           <!-- 2)  <p ng-show="{{list.txt}}"> <br><ul><li>previous values:</li> <li ng-repeat="list in alerts.list">{{list.txt}}</li></ul> </p>-->                          </td></tr>                  </tbody> 

i tried 2 approaches seen in code. first 1 displayed list correct displayed underneath every long message instead of 1 belongs to. used new variable.

var l=vallist.length; scope.list=true; while(l>-1){     scope.valuelist.push({value: vallist[l]});     l--; } 

the second approach did not work @ because not find index.

 var l=vallist.length;        var indexv= jquery.inarray(currdate,scope.alerts.date);         while(l>-1){             scope.alerts[indexv].list.push({txt: vallist[l]});             l--;         } 

edit: current output. there can see 2 objects( date, short message , long message) , both of them have previous values section. upper object supposed diplay list of previous values.

what trying achieve entirely possible, advice start @ known point , work there.

i have put jsfiddle show how nested ng-repeats work. try , work point. side note looks json structure overly complex, if can simplify down would.

https://jsfiddle.net/roscorcoran/wyu7tgxm/

<div ng-app="app" ng-controller="ctrl1">   <div ng-repeat="alert in alerts">     <a ng-if="alert.date">{{alert.date}}</a>      <p ng-repeat="val in alert.l.vals">       <a ng-if="val && val.value">{{val.value}}</a>     </p>      <p ng-repeat="item in alert.list">       <a ng-if="item && item.txt">{{item.txt}}</a>     </p>   </div> </div> 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -