2016-07-14 4 views
0

私は、バックエンドデバイスによって投げられた例外と警告を含むリストグループを作成しています。 list-groupは、フィールド「type」でコレクションを読み取ります。このタイプフィールドには、警告またはエラーを含めることができます。警告/エラーに基づいて、流星の中にlist-group-item-danger/list-group-item-warningを設定するにはどうすればよいですか?HTMLタグのクラスをmongoに基づいて設定すると流星になります

モンゴコレクションは、次のようになります。私はlist-group-itemリスト・グループ・アイテム - 組み込むにはどうすればよい

<a href="#" class="list-group-item clearfix"> 
     <i class="fa fa-comment fa-fw"></i> {{ message }} 
     <div class="pull-right text-muted small"><em>{{timestamp}}</em> 
     </div> 
    </a> 

を:

{ type:"red", timestamp: new Date(), message:"something happened 3"} 

マイリスト・グループ項目は、次のようになります危険based on type = red`がmongoによって返されましたか?

答えて

0

私は流星フォーラムの助けを借りて考え出しました。

テンプレート:

... 
<a href="#" data-toggle="modal" data-target="#alertModal" class="{{listGroupClass}} clearfix"> 
... 

ヘルパー:

Template.alert.helpers ({ 
    listGroupClass: function() { 
     if (this.type == "red") { 
      return "list-group-item list-group-item-danger"; 
     }else 
     if (this.type == "warning") { 
      return "list-group-item list-group-item-warning"; 
     }else 
     if (this.type == "info") { 
      return "list-group-item list-group-item-info"; 
     } 
    } 


}); 
関連する問題