I have a an array of locations and each location has several events. I would like to offer the user the ability to remove the entire location along with the location's events. I have this working using $remove. I would also like to offer the user the ability to remove a single event from a location. This is where I'm stuck.
Here is the html:
<div class="wrapper" v-for="location in locations">
<h2>
{{ location.id}}: {{ location.street_address }}
<a href="javascript:;" @click="deleteLocation(location)">
<i class="fa fa-trash pull-right"></i>
</a>
</h2>
<hr>
<ul>
<li v-for="event in location.events">
{{ event.location_id }}.{{ event.id }}: {{ event.title }}
<a href="javascript:;" @click="deleteEvent(event)">
<i class="fa fa-trash pull-right"></i>
</a>
</li>
</ul>
</div>
And here is the javascript:
new Vue({
el: 'body',
data: {
locations: [{
id: 1,
street_address: '123 Oak',
events: [{
id: 1,
location_id: 1,
title: 'Oak Street Event 1'
}, {
id: 2,
location_id: 1,
title: 'Oak Street Event 2'
}]
}, {
id: 2,
street_address: '456 Pine Street',
events: [{
id: 3,
location_id: 2,
title: 'Pine Street Event 1'
}, {
id: 4,
location_id: 2,
title: 'Pine Street Event 2'
}]
}, {
id: 3,
street_address: '789 Elm Street',
events: [{
id: 5,
location_id: 3,
title: 'Elm Streem Event 1'
}, {
id: 6,
location_id: 3,
title: 'Elm Street Event 2'
}]
}]
},
methods: {
deleteLocation(location) {
this.locations.$remove(location);
console.log(location);
},
deleteEvent(event) {
this.locations.events.$remove(event);
console.log(event);
}
}
And here is a fiddle JSFiddle
If someone could take a look I would really appreciate it!