如何在vue js中显示评级值?

时间:2017-12-09 07:15:20

标签: javascript jquery vue.js vuejs2 vue-component

我的json数据是

{"status": true, "reviews": [{"review": "scdbgnhvgdbsr", "rating": 5, "by": "aravind", "pid": 8, "review_id": 1}, {"review": "helsocxdxvfbgfnhfgdf", "rating": 2, "by": "ab", "pid": 8, "review_id": 2}], "rating": 3.5}

我能够显示"评级"以外的所有细节。这是数据[]之外的。我怎样才能显示评分。在这里,我需要显示评分= 3.5

<div id="feed"> <div v-for="row in reviews">{{row.review}} </div> </div>

我的vue js脚本是

 new Vue({ 
 el: '#feed' , 
 data: { 
 data: [], 
 reviews: [],
 pid: '{{pid}}',
 }, 
 mounted() { 
var self = this; 
 const data = {}
 data['pid'] = this.pid;
 $.ajax({ 
 url: "http://127.0.0.1:8000/api/post/reviews/", 
 data: data,
 type: "POST",
 dataType: "JSON", 
 success: function (e) { 
 if (e.status == 1) { 
  self.reviews = e.reviews;
  console.log(self.reviews);
}
}
});
},
})

1 个答案:

答案 0 :(得分:1)

var obj = jQuery.parseJSON( '{"status": true, "reviews": [{"review": "scdbgnhvgdbsr", "rating": 5, "by": "aravind", "pid": 8, "review_id": 1}, {"review": "helsocxdxvfbgfnhfgdf", "rating": 2, "by": "ab", "pid": 8, "review_id": 2}], "rating": 3.5}' );
alert( obj.rating);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>