javascript - Vue JS - Remove an object from the data array -


i using vuejs display active users in site. when user becomes active, pusher sends json details -

{       "token": "97lbfns7pfpbzvlo",       "first_name": "joe",       "last_name": "smith",       "avatar": "http://demo.com/avatar.jpg",       "phone": "255-255-2555",       "available" : true,       "agencies": [         {           "name": "some company",           "slug": "some-company"         }       ]     } 

when user signs out, token sent along available: false. need remove them vue data array, stuck.

here data array in vue js (pretty basic):

data: {       responders: [] } 

update here basic idea of i'm trying accomplish, outside of vue methods. need remove item data array, think more of javascript related issue more specific vue.

@michaelsnowden made suggestion store users objects instead of array i'm not sure how accomplish this. have attempted:

adduser: function() {             var user = {'asdasdasdop': {name: "joe"}};             this.users.push(user);         } 

which gives me:

"users": [     {       "asdasdasdop": {         "name": "joe"       }     }   ], 

but beyond cannot figure out how access these values or remove item array based on token. appreciated - i've had no issues adding cannot life of me figure out how remove something.

vue augments watched arrays $remove method takes numerical index parameter. can find index like:

var usertoken ='potato'; var tokentoremove; users.foreach(function(user, index) {     if(usertoken === user.token) {          tokentoremove = index;     } });  users.$remove(tokentoremove); 

so find in way can index of user token potato , , use $remove method.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -