繁体   English   中英

流星助手使用基于反应变量的查询

[英]Meteor Helper using query based on reactive variable

我正在尝试使用一个帮助程序,该帮助程序应使用templates:array的反应数组返回一个集合,该集合使用$in指定整个集合的子集。

我有

var tags = new ReactiveArray();

在某些情况下,我更改了数组的内容,类似于

tags.pushArray(note.tags);

(或者我应该使用.set()吗?)

我的助手是

Template.editor.helpers({
    tagslist() {
        return Tags.find({ _id: { $in : tags }});
    }, 
});

但是然后我在meteor.js:1010得到了一个异常,看起来像这样

if (allArgumentsOfTypeString)
   console.log.apply(console, [Array.prototype.join.call(arguments, " ")]);

在堆栈中有compileValueSelector 这似乎表明帮助程序的编译对所找到的内容不满意。

我还尝试使tags成为模板本地实例,并将.get()添加到帮助器查询中的tags 但结果相同。

我应该从哪里开始寻找? 我是否正确使用ReactiveArray? 是否可以做我想做的事,即有一个基于ReactiveArray的反应式查询?

我个人没有使用过ReactiveArray,但我认为相同的模式也可以。 我坚持使用ReactiveVar,因此这里有一个示例,可以使您朝正确的方向前进。

Template.editor.onCreated(function () {
    const instance = this;
    instance.tags = new ReactiveVar([]);
});

Template.editor.helpers({
    tagslist() {
        const tags = Template.instance().tags.get();
        return Tags.find({ _id: { $in : tags }});
    }
});

Template.editor.events({
    'click .tag'(event, instance){
        const tag = this;
        const tags = instance.tags.get();
        tags.push(tag);
        instance.tags.set(tags);
    }
});

暂无
暂无

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

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