繁体   English   中英

蒙哥拉流星不拉

[英]Mongo pull in Meteor not pulling

我一直在尝试从Mongo的Meteor中提取一个数组,但是我似乎无法使其工作。 我能够做到这一点。 任何帮助将不胜感激。 这是我的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>

这是用于推送的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");

这里是我拉:

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

编辑:

通过单击“ #add_event”按钮将新值推送到集合中。 然后,它将“ #schedule”输入的值推入“ schedule”数组。

试图通过单击“ .listExRemove”按钮删除值。 然后,它在父容器中查找“ .schedule_item_info”文本,并将其保存在“ the_text”变量中。 接下来,它应该从“时间表”数组中拉出“ the_text”,并在控制台中显示“ the_text”。

它在控制台中显示“ the_text”,但不会从集合中提取它。 我没有收到任何错误,警告等。我尝试将其推入不同的数组变体中,并且没有成功。 我也尝试过用一个我知道该数组中没有的字符串替换“ the_text”。

事实证明,由于“ listExRemove”按钮处于{{#each}}循环中,因此“ this._id”没有获取模板的ID。 为了获得ID,我改用“ template.data._id”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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