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