我正在尝试访问Vue.js中的以下数据
{"id":1,"name":"Westbrook","created_at":"2017-06-10T16:03:07.336Z","updated_at":"2017-06-10T16:03:07.336Z","stats":[{"id":1,"player_id":1,"points":2558,"assists":840,"rebounds":864,"created_at":"2017-06-10T16:03:07.373Z","updated_at":"2017-06-10T16:03:07.373Z"}]}
self.player = response.name
作品。现在我需要self.point
methods: {
fetchData: function() {
var self = this;
$.get("api/v1/players/1", function(response) {
console.log(response);
self.player = response.name;
self.point = response.stats.points
});
}
}
我迄今尝试过response.stats["points"]
,response.stats[2]
,response.stats[ { points } ]
,response.stats[points]
stats
json中的属性包含一个数组,其中第一个对象具有名为points
所以用 response.stats[0].points
请记住,尽管stats
可能是数组是有原因的。将来可能包含多个对象,因此始终使用第一个元素[0]
可能不是有效的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句