简体   繁体   English

如何访问json响应的各个组件-Angular

[英]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.

相关问题 如何在Angular 5中使用HttpClient访问响应标头? - How do I access response headers using HttpClient in Angular 5? 如何使用角度js正确显示JSON响应? - How do I properly display a JSON response using angular js? 如何在此JSON响应中访问browser和browser_version? - How do I access browser and browser_version in this JSON response? 如何访问JSON API响应中的嵌套信息? - How do I access nested information in a JSON API response? localstorage json 行我如何访问每一行及其各个元素 - localstorage json rows how do i access each row and their individual elements 如何使用新的HttpClient访问Angular 4.3中的json键? - How do I access json key in Angular 4.3 with the new HttpClient? 如何在Angular JS的控制器中访问JSON的子元素 - how do I access child elements of JSON in the controller in Angular JS 如何获得单个Angular组件的可寻址性? - How to get addressibility to individual Angular components? 无法访问JSON对象中的单个数据:如何从JSON对象中将数据选出到VUE中 - Can't access individual data in JSON object: how do I single out data form a JSON object into VUE Angular 1.3.0支持JSON响应,如何在Angular之前覆盖它或预先解析响应? - Angular 1.3.0 honors JSON responses, how do I override this or pre-parse the response before Angular?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM