abu abu
abu abu

Reputation: 7022

Filter in PROPS in vue.js

I have code like below

created () {
     EventBus.$on('change',this.formated);
},
props: ['applicants',],
data() {
        return {
            values: [],
      }
},
methods : {
        formated (item) {
         //some code here
        }
}

I have some checkboxes in another component. I am trying to catch values of those checkboxes in this component. After catching those values I would like to filter the props applicants. I would like to find out which applicants have those values of checkboxes. Then I would like to pass them to values[]. Then I would like to iterate those values in HTML.

Upvotes: 0

Views: 2084

Answers (1)

Imre_G
Imre_G

Reputation: 2535

After reading the comments I believe this is what you need to do. You can use the prop as well as the data passed through the event bus in the formatted() method. You need to combine the two and set them to values. I have pasted code below. However, not knowing the structure of either two objects I can't help you further. This is just plain JavaScript. So probably you need something like Object.assign or the .filter or .map methods.

created () {
 EventBus.$on('change',this.formatted);
},
props: ['applicants'],
data() {
    return {
        values: [],
      }
},
methods : {
    formatted (item) {
        this.applicants // access the data from your prop
        item // access the data from your event bus
        this.values = someCombinationOf(this.applicants, item)
    }
}

After setting values from the formatted () function you can iterate over it (for example with v-for). Whenever an event is emitted through the event bus this will update your component. Whenever the prop changes the component will be updated also.

Upvotes: 1

Related Questions