I have a Personnel table bound to an array of objects that is coming from VueJs. The last column on the table is a button for editing each record.
I'd like to show a modal popup when the edit button is clicked and bind the textboxes to the properties of the personnel that I want to edit. It should update the table and the source of the data when the save button on the modal popup is clicked.
But I am stuck on passing the object or even just the key to the component so I can load the data or bind the edited object into my textboxes.
JS
var app = new Vue({
el: '#my-app',
data: {
personnels: [
{
id: 1,
firstName: 'Billy',
lastName: 'Bob',
email: '[email protected]'
},
{
id: 2,
firstName: 'Mike',
lastName: 'Coilers',
email: '[email protected]'
},
{
id: 3,
firstName: 'Fred',
lastName: 'Just',
email: '[email protected]'
},
{
id: 4,
firstName: 'Tori',
lastName: 'Drury',
email: '[email protected]'
}
]
},
methods: {
showPersonnelEditor: function () {
// how do i pass data to the personnelEditor component?
}
}
});
Vue.component('personnel-editor', {
prop: ['personnel']
});
HTML
<div id="my-app">
<table classs="table" width="100%">
<tr>
<th>
Id
</th>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>
Email
</th>
<th>
Actions
</th>
</tr>
<tr v-for="personnel in personnels">
<td>
{{ personnel.id }}
</td>
<td>
{{ personnel.firstName }}
</td>
<td>
{{ personnel.lastName }}
</td>
<td>
{{ personnel.email }}
</td>
<td>
<button v-on:click="showPersonnelEditor">Edit</button>
</td>
</tr>
</table>
<personnel-editor inline-template><div class="modal fade" >
<div class="modal-dialog">
<div class="modal-header">
header
</div>
<div class="modal-content">
<div class="form-group row">
<div class="col-lg-12">
<label>Id</label>
<input type="text" v-model="personnel.Id" />
</div>
<div class="form-group row">
<div class="col-lg-12">
<label>First Name</label>
<input type="text" v-model="personnel.firstName" />
</div>
</div>
</div>
<div class="form-group row">
<div class="col-lg-12">
<label>Last Name</label>
<input type="text" v-model="personnel.lastName" />
</div>
</div>
<div class="form-group row">
<div class="col-lg-12">
<label>Email</label>
<input type="text" v-model="personnel.Email" />
</div>
</div>
</div>
<div class="modal-footer">
oh mah foot
</div>
</div>
</div>
</div></personnel-editor>