简体   繁体   中英

Mongo pull in Meteor not pulling

I've been trying to pull an array from Mongo inside of Meteor, but I can't seem to get it to work. I'm able to push to it fine. Any help would be greatly appreciated. Here's my html:

<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>

Here is the javascript for pushing:

    '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");

And here is me pulling:

'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 are being pushed into the collection by clicking the "#add_event" button. It then pushes the value of the "#schedule" input into the "schedule" array.

Values are trying to be removed by clicking the ".listExRemove" button. It then looks in the parent container for the ".schedule_item_info" text, and saves it in the "the_text" variable. Next it should pull "the_text" from the "schedule" array, and display "the_text" in the console.

It displays "the_text" in the console, but doesn't pull it from the collection. I'm not receiving any errors, warnings, etc. I've tried pushing into different array variations and pulling without success. I've also tried replacing "the_text" with a string I know is in the array to no avail.

It turns out since the "listExRemove" button was in an {{#each}} loop, "this._id" wasn't getting the id of the template. In order to get the id I used "template.data._id" instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM