javascript - How to filter two data set from one selection in VueJs -




i'm building small application in vuejs 2.0 i'm having 2 select options select2 plugin such:

<div class="form-group"><label class="col-sm-2 control-label">categories:</label>     <div class="col-sm-4">         <v-select multiple :options="selecttable" placeholder="categories"  v-model="categories"></v-select>     </div>  </div> <div class="hr-line-dashed"></div> <div class="form-group"><label class="col-sm-2 control-label">sub-categories:</label>     <div class="col-sm-4">         <v-select multiple :options="selectsubtractedtable" placeholder="subtracted categories"  v-model="subtractedcategories"></v-select>     </div>  </div> 

now i've computed property list these elements inside, like:

computed: {     selecttable() {         if(this.model)         {             return this.model.map(a => ({                 value: a.id,                 label: a.name             }));         }     },     selectsubtractedtable() {         if(this.submodel)         {             return this.submodel.map(a => ({                 value: a.id,                 label: a.name             }));         }     } }, 

now i'm having watch function checks first list , remove elements second list as:

watch: {     categories(newvalue) {         this.submodel = this.model         for(var = 0; i<newvalue.length; i++ )         {             const element = this.submodel.find(a => a.id == newvalue[i].value)             console.log(element)             if(element>0)                 this.submodel.splice(index, 1)         }     } } 

i've data set in following format:

this.model = this.submodel = [     {         "id":1,"name":"jeans","created_at":null,"updated_at":null     },     {         "id":2,"name":"shirts","created_at":null,"updated_at":null     },     {         "id":3,"name":"top","created_at":null,"updated_at":null     },     {         "id":4,"name":"women","created_at":null,"updated_at":null     },     {         "id":5,"name":"men","created_at":null,"updated_at":null     },     {         "id":6,"name":"jwellary","created_at":null,"updated_at":null     } ] 

and const element = this.submodel.find(a => a.id == newvalue[i].value) showing value 0 in watch property

help me out.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -