我如何使流星助手无反应? [英] How Do I Make A Meteor Helper Non-Reactive?

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

问题描述

我想让这段代码没有反应.有办法吗?

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 was wondering if there was a equivalent.

推荐答案

我想你正在寻找的是 Tracker.nonreactive(func) 描述的函数 此处.根据文档,您需要将一个函数传递给要执行的函数,该函数的结果将由该函数返回.此外,此函数不会关注您自己定义的函数中的任何反应式数据源更新.

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天全站免登陆