Struggling to retrieve an array from Mongo within Meteor, despite successful push operations. Any assistance would be greatly valued. Below is the HTML code:
<ul class="schedule">
{{#each employee.schedule}}
<li class="schedule_item"><a class="btn listExRemove" title="Remove this name">x</a><p class="schedule_item_info">{{ . }}</p></li>
{{/each}}
</ul>
<div class="form-group form-md-line-input">
<input type="text" name="schedule" value="" class="form-control" id="schedule" placeholder="Enter the schedule" >
<label for="item">Schedule</label>
</div>
<a href="" class="btn btn-red" id="add_event">Add</a>
For pushing, here's the corresponding JavaScript:
'click #add_event': function(event, template) {
var id = this._id; // Set equal to the current id
var push_it = $('#schedule').val();
Employees.update({_id:id}, {
$push: {
schedule: push_it
}
});
console.log("It's updated");
For pulling functionality:
'click .listExRemove': function(event, template) {
var id = this._id; // Set equal to the current id
var the_text = $(event.target).parent().find('.schedule_item_info').text();
Employees.update({_id: id}, {
$pull: {
schedule: the_text,
}
});
console.log(the_text);
Edit:
New values can be pushed into the collection by clicking the "#add_event" button. It retrieves the value of the "#schedule" input and adds it to the "schedule" array.
To remove values, users can click the ".listExRemove" button. The script looks for the text within the ".schedule_item_info", stores it in "the_text", then attempts to pull "the_text" from the "schedule" array and displays it in the console.
The text is displayed in the console but not successfully removed from the collection. No errors or warnings are being thrown. Various methods have been attempted, including using different array variations and replacing "the_text" with known strings without success.