angular - How to parse json on angular2? -
i`ve parsed code,
[ {"nodename":"192.124.105.55", "servicelist":[ { "id":"ec9471ec001c10b9fa286e1f52e39c5dc9485a7c2cfbf55145c26242bb98ec4d", "name":"nginx", "status":"online", "servicecontrolled":true }, { "id":"f4ca9e0badc6b23e3e36444bd7ee4a9efcd39de8e0bb4cdecb25b5a02ef86ba5", "name":"memcached", "status":"offline", "servicecontrolled":true }, { "id":"0a4bf3b5bb5f47ece9284052389ae02f6c9dba989ca34086a30e049ee3d8eb47", "name":"celery", "status":"offline", "servicecontrolled":true } ], "storagelist": [ { "mountpoint":"/", "total":188, "used":28, "free":161 }, { "mountpoint":"/boot", "total":235, "used":106, "free":129 } ], "system": { "memory": { "total":33673834496, "used":14725959680, "free":18947874816, "actualfree":24221499392, "actualused":9452335104, "swaptotal":34296819712, "swapused":0, "swapfree":34296819712 }, "uptime":" 4:09", "loadaverage":"0.91 0.49 0.54", "cpu": { "vendor":"genuineintel", "family":"6", "model":"intel(r) xeon(r) cpu e5620 @ 2.40ghz", "rate":"2399.971", "numofcores":2 } } }, {"nodename":"192.124.105.58", "servicelist":[ {"id":"428d3cc1d4d7218d6b9d1a80152179fac0aba40e2eee5525befe1355919db5e6", "name":"nginx", "status":"online" }, { "id":"9f71381ff2e2181b4dde841e85d7d29af33fc2bd1929092aedf237d124ae75e0", "name":"memcached", "status":"online" }, { "id":"c7dc289c490b8087d47971a45d545fcbbf7f425b1087179ae4a05c585c859302", "name":"gunicorn", "status":"online" }, { "id":"a96c90d2423c4e300d8d1d83b2e4dfdd70af9ca0ae91bdba35a66dd9ffa2f572", "name":"test", "status":"offline" } ], "storagelist": [], "system": { "memory": { "total":12425734566, "used":4725959680, "free":8947874816, "actualfree":4221499392, "actualused":452335104, "swaptotal":4296819712, "swapused":0, "swapfree":4296819712 }, "uptime":" 12 days, 4:09", "loadaverage":"0.00 0.00 0.00", "cpu": { "vendor":"genuineintel", "family":"6", "model":"intel(r) xeon(r) cpu e5620 @ 2.40ghz", "rate":"2399.971", "numofcores":4 } } } ]
"nodename", "servicelist", "storagelist" ok, "system" , "memory" dont parsed.
this html ->
<h1> Мониторинг сервисов (m.s.a) </h1> <table class="table table-bordered" *ngfor="let list of lists"> <caption>{{ list.nodename }}</caption> <thead> <tr> <th>Название сервиса</th> <th></th> <th>Операции</th> <th>Статус</th> </tr> </thead> <tbody> <tr *ngfor="let service_rec of list.servicelist"> <td> {{ service_rec.name }} </td> <td></td> <td></td> <td style="width: 15%"> <span [style.background-color]="service_rec.status == 'online' ? 'green' : 'red'" class="label label-default"> {{ service_rec.status }} </span> </td> </tr> </tbody> <thead> <tr> <th>Файловая система</th> <th>Всего</th> <th>Использовано</th> <th>Доступно</th> </tr> </thead> <tbody> <tr *ngfor="let service_rec of list.storagelist"> <td> {{ service_rec.mountpoint }} </td> <td> {{ service_rec.total | byteformat }} </td> <td> {{ service_rec.used | byteformat }} </td> <td> {{ service_rec.free | byteformat }} </td> </tr> </tbody> <thead> <tr> <th>Общая память</th> <th>Общая используемая память</th> <th>Свободная память</th> <th>Используемая память размера подкачки</th> </tr> </thead> <tbody> <tr *ngfor="let perem of system.memory"> <td> {{perem.total}} </td> <td> {{perem.actualused}} </td> <td> {{perem.actualfree}} </td> <td> {{perem.swapused}} </td> </tr> </tbody> </table>
how parse json? pipe? , how can parse "cpu"?? know que. popular on stackovetflow, cants find problem
it's because ngfor
accepts arrays , not objects. object correctly parsed system.memory
can't handled...
"system": { "memory": { (...) } // <----- object
if want iterate on keys in object, need implement custom pipe.
this question you:
Comments
Post a Comment