[英]How do I access individual components of json response - Angular
I have a controller that returns a json array with one index in it - a json string containing three different properties - whiteLedvalue - blueLedValue - variousColorLedValue. 我有一个控制器,它返回一个带有一个索引的json数组-包含三个不同属性的json字符串-whiteLedvalue-blueLedValue-VariousColorLedValue。
In my controller I have something like this: 在我的控制器中,我有类似以下内容:
function getLedData()
{
ledService.getLedData()
.then(function(response){
ctrl.ledData = response.data;
});
}
And in my dashboard HTML file I have this: 在我的仪表板HTML文件中,我有以下内容:
`<tr ng-repeat="led in ctrl.ledData">
<td> LED Value</td>
<td >
{{ led }}
</td>
</tr>`
I would like to access just the white values and place them in a td and then the blue in another td etc.... 我想只访问白色值并将它们放在一个td中,然后将蓝色放在另一个td中,等等。
I tried this: 我尝试了这个:
`<tr ng-repeat="led in ctrl.ledData.whiteLedValue">
<td> LED Value</td>
<td >
{{ led }}
</td>
</tr>`
And it did not work. 而且它没有用。 I assume it has something to do wiht the fact that I am returning an array and I need to access the correct index.
我认为这与我要返回一个数组并且需要访问正确的索引有关。 But I cannot seem to figure out if I'm supposed to set the white/blue/various values to their own ctrl.whatever or I should try to access them within the html.
但是我似乎无法弄清楚是否应该将白色/蓝色/各种值设置为它们自己的ctrl。无论如何还是应该尝试在html中访问它们。 Any help on getting these individual fields would be great.
获取这些单独字段的任何帮助都将非常有用。 The only way I can get it to work is by returning the entire json string.
我可以使它工作的唯一方法是返回整个json字符串。
Did you parse the json-string to a javascript array yet? 您是否已将json-string解析为javascript数组?
ctrl.ledData = JOSN.parse(response.data);
Further reading: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse 进一步阅读: https : //developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.