简体   繁体   中英

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?

Here is the screenshot about the json file: JSON File

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

includes is a method of Object of Array type. Directly judge attribute reviewed is OK

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.questions.length

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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