简体   繁体   English

Vue js:过滤动态数据

[英]Vue js : Filter dynamic data

In my Vuejs below I want to filter the reviewed:true only questions, and get the length of them, but my code below gives an error TypeError: question.reviewed.includes is not a function ,is there a way to do it?在我下面的 Vuejs 中,我想过滤已reviewed:true only 问题,并获取它们的长度,但是我下面的代码给出了错误TypeError: question.reviewed.includes is not a function ,有没有办法做到这一点?

Here is the screenshot about the json file: JSON File这是关于 json 文件的屏幕截图: JSON 文件

 filterReviewed() { return this.questions.filter((question) => { return ( question.reviewed.includes('true') ); }); },

includes is a method of Object of Array type. includes Array类型的 Object 的方法。 Directly judge attribute reviewed is OK直接判断属性reviewed即可

filterReviewed (){
  return this.questions.filter((question) => question.reviewed);
}

To filter the reviews try this:要过滤评论,请尝试以下操作:

filterReviewed() {
          return this.questions.filter((question) => question.reviewed === true);
        },

To get the filterReviewed length try this:要获得 filterReviewed 长度,请尝试以下操作:

filterReviewed.questions.length

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM