I'm trying to save the specific objects in an array that has the checkbox 'checked'. I want to create the new array so I can use only those latter.
How can I do that using jquery?
'use strict';
class event {
constructor(jQuery) {
this.$ = jQuery;
}
getEvents(eventKey) {
let aEvents = [{
eventName: 'ABDCCC',
// true = checked
status: true
},
{
eventName: 'ACC',
status: true
}
];
return aEvents;
/**
* Update
* @param {array} [aEvents]
*/
setEvents = function(aEvents) {
// Put them on a table
var table = this.$('#eventsTable');
table.find('tbody tr').remove();
for (var i = 0; i < aEvents.length; i++) {
let event = aEvents[i];
table.find('tbody').append(`
<tr>
<td>
${event.eventName}
</td>
<td>
<div id="check-list" class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" ${event.status ? 'checked' : ''} id="customSwitch${i}"/>
<label class="custom-control-label" for="customSwitch${i}"></label>
</div>
</td>
</tr>
`);
}
}
}
I want to get this result
- You can check the Events you like (done)
- When click on a button ('save this events' for ex) only the checked events will be saved on a new array of objects, the same ones in getEvents()