gpt4 book ai didi

javascript - 从数组中删除项目不起作用

转载 作者:可可西里 更新时间:2023-11-01 10:29:39 26 4
gpt4 key购买 nike

我正在尝试从数组中删除标签。但我无法让它工作——什么也没有发生。 console.log 输出似乎是正确的。谢谢!

事件处理器

Template.doc.events({
'click .remove': function(event, template) {
console.log("This doc's _id: " + template.data._id);
console.log("doc's tags: " + template.data.metadata.tags);

var thisTag = this;
console.log("thisTag: " + thisTag);

MyPix.update (
template.data._id,
{ $pull: { 'template.data.metadata.tags': thisTag }},
{ multi: true }
);
},
});

模板

<template name="doc">
<ol><li>
<span class="property">metadata.tags</span>:
{{#each this.metadata.tags}}
<span class="tag"><span class="remove">X</ span>{{this}}</span>
{{/each}}
</li></ol>
</template>

最佳答案

乍一看,拉取中的字段标识符似乎不正确。在这里您必须使用 MongoDB 标识符,而不是属于您的对象的标识符。尝试更改

template.data.metadata.tags

metadata.tags

在拉取调用中。

关于javascript - 从数组中删除项目不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28525354/

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