如何使流星助手不活跃? [英] How Do I Make A Meteor Helper Non-Reactive?

查看:97
本文介绍了如何使流星助手不活跃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使此代码无反应.有办法吗?

I want to make this code non reactive. Is there a way?

Template.foo.helpers({
    info: function(){
        var user = Meteor.user();
            if (user && user.profile)
                return user.profile.info;
    }
});

我知道有一种方法可以使您Foo.find({}, {reactive:false})

I know there is a way when you are Foo.find({}, {reactive:false})

我想知道是否有一个等价物.

I was wondering if there was a equivalent.

推荐答案

我认为您正在寻找的是

I think what you are looking for is the Tracker.nonreactive(func) function described here. Per the documentation, you need to pass a function to this function to be executed and the result of that function will be returned by this function. Also, this function will not pay attention to any reactive data source updates in your own defined function.

我建议像这样重写您的辅助函数:

I would suggest rewriting your helper function like this:

Template.foo.helpers({
    info: function() {
        return Tracker.nonreactive(function() {
            var user = Meteor.user();
            if(user && user.profile) {
                return user.profile.info;
            } else {
                // return some other appropriate value if the if-statement above
                // is not fulfilled
            }
        });
    }
});

这篇关于如何使流星助手不活跃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆