gpt4 book ai didi

javascript - Mongo 拉入 Meteor 不拉动

转载 作者:行者123 更新时间:2023-12-03 09:02:41 27 4
gpt4 key购买 nike

我一直在尝试从 Meteor 内部的 Mongo 中提取一个数组,但我似乎无法让它工作。我能够很好地插入它。任何帮助将不胜感激。这是我的 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”变量中。接下来,它应该从“schedule”数组中提取“the_text”,并在控制台中显示“the_text”。

它在控制台中显示“the_text”,但不会将其从集合中提取。我没有收到任何错误、警告等。我尝试插入不同的数组变体并拉取,但没有成功。我还尝试用我知道数组中的字符串替换“the_text”,但无济于事。

最佳答案

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

关于javascript - Mongo 拉入 Meteor 不拉动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32261142/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com