2016-08-31 7 views
1

変数が変更された後、テンプレートの一部をリフレッシュ/リロードして、変数がtrueの場合はコンテンツAを表示します。そうでない場合はコンテンツBが表示されます。これは非常に簡単な質問ですが、私は解決策を見つけるのに苦労しています。このような変数変更後のメテオ - リロードテンプレートセクション

何か:

Template.x.created = function() { 
    this.variable = false; 
} 

Template.x.helpers({ 
    'getValue': function(){ 
      return this.variable; 
     } 
}); 

テンプレート:あなたが再実行するテンプレートヘルパーを取得するために反応性のデータソースを作成する必要が

<template name="x"> 
    {{#if getValue}} 
    <content A> 
    {{else}} 
    <content B> 
    {{/if}} 
</template> 

答えて

1

とき、通常の変数として変数の変化、ヘルパーが値を変えたときにそれを知らせることはありません。最も簡単な解決策は、ReactiveVarを使用することです:

Template.x.onCreated(function() { 
    this.variable = new ReactiveVar(false); 
}); 

Template.x.helpers({ 
    'getValue': function() { 
    // Note that 'this' inside a template helper may not refer to the template instance 
    return Template.instance().variable.get(); 
    } 
}); 

このテンプレート外のどこかで値にアクセスする必要がある場合は、代替反応性データソースとしてSessionを使用することができます。

関連する問題