相关疑难解决方法(0)

Meteor - 如何在帮助程序和模板事件之间传递数据?

我对Meteor有点新意,我遇到的问题是反应数据 - 特别是在我需要根据鼠标或键盘事件更改显示的数据的情况下.正常的js方式做这种事情似乎让我在流星上遇到麻烦,因为我改变的一切都会被重新渲染并不断重置.

所以,我想我会看到这是否可以使用Meteor的Deps对象,但是我无法理解它.这是我正在使用的代码:

(function(){

    var tenants = [];
    var selectedTenant = 0;

    var tenantsDep = new Deps.Dependency;

    Template.tenantsBlock.tenantsList = function()
    {
        tenants = [];
        var property = $properties.findOne({userId: Meteor.userId(), propertyId: Session.get('property')});
        var tenancies = _Utils.resolveTenancies(property, true, null, true);

        for(var i = 0; i < tenancies.length; i++)
        {
            if(tenancies[i].tenancyId == Session.get('tenancy'))
            {
                tenants = tenants.concat(tenancies[i].otherTenants, tenancies[i].primaryTenant);
            }
        }

        tenants[selectedTenant].selected = 'Selected';

        tenantsDep.changed();

        return tenants;
    };

    Template.tenantsBlock.onlyOneTenant = function()
    {
        tenantsDep.depend();

        return tenants.length > 1 ? '' : 'OneChild';
    };

    Template.tenantsBlock.phoneNumber …
Run Code Online (Sandbox Code Playgroud)

reactive-programming meteor

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

meteor ×1

reactive-programming ×1