javascript - 如何在vue js中显示评分值?

标签 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);
}
}
});
},
})

最佳答案

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>

关于javascript - 如何在vue js中显示评分值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47726290/

相关文章:

javascript - 在 contentEditable 中将 HTML 转换为纯文本

javascript - 使用 VUEX 将嵌套数据添加到 Firebase

javascript - 将今天的日期作为隐藏的表单输入值提交

javascript - 使用 jQuery 左右移动图像

javascript - Node.js HTTP 代理架构 : downloading big amount of data for client

javascript - 通过 id React 私有(private)路由

javascript - 使用 jquery done on "non-ajax"函数

javascript - 在 IE 和 Firefox 中出现花式框问题

javascript - 父数据未在 vue.js 组件中定义

vue.js - VueJS 通过 v-for 与父容器通信,提供索引和参数