【问题标题】:How to display value of rating in vue js?如何在vue js中显示评分值?
【发布时间】:2018-05-23 09:41:27
【问题描述】:

我的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);
}
}
});
},
})

【问题讨论】:

  • reviews 是如何定义的?
  • 先生,我可以打印除 json 数据最后的评分以外的所有数据
  • 也许只是rating?能否分享一下你的 vue 组件是如何定义的?
  • 是的评级......
  • 我用 vue js 代码更新了问题

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


【解决方案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);
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2021-07-25
    • 2020-09-19
    • 1970-01-01
    相关资源
    最近更新 更多