简体   繁体   English

流星-基于收藏价值的新行?

[英]Meteor - New row based on collection value?

I'm trying to create a result where if a value in the collection is specified such as "New Row" That I create a new tag. 我试图创建一个结果,如果在集合中指定了一个值(例如“ New Row”),那么我将创建一个新标签。

Problem is if I use a helper I can't wrap the Start DIV in a Handle bar helper function. 问题是,如果我使用帮助器,则无法将“开始DIV”包装在“把手”帮助器功能中。 Separately from the Child of that DIV. 与那个DIV的孩子分开。

        {{#each myPostImages}}
        New Row: {{#if newrow}}
        <div class="row postee">    
                        <div class="col-xs-8 middlePost">
                   <img src={{url}}>
                </div>
            </div>
        </div>                      
        {{/if}}



        {{/each}}

What can I do to some time not output the as sometimes I want the next value in the collection to be contained in the same row.....? 我有时会不输出做什么,因为有时我希望集合中的下一个值包含在同一行中.....?

I'm trying to create this result: 我正在尝试创建以下结果:

        <div class="row postee">    
                <div class="col-xs-8 middlePost">
                   <img src={{url}}>
                </div>
                <div class="col-xs-8 middlePost">
                   <img src={{url}}>
                </div>
                    <div class="col-xs-8 middlePost">
                   <img src={{url}}>
                </div>
            </div>
        </div>                      
        <div class="row postee">
                <div class="col-xs-8 middlePost">
                   <img src={{url}}>
                </div>
        </div>

You can solve, of the following way 您可以通过以下方式解决

your archive .httml 您的档案.httml

 <template name="myPost">    
       {{#each myPostImages}}
        New Row: 
          {{#if newrow this}}
             <div class="row postee">  
               {{#each this.url}}
                  <div class="col-xs-8 middlePost">
                      <img src={{this}}>
                  </div>
               {{/each}}
             </div>
          {{else}}
             ....
          {{/if}}
        {{/each}}
 </template>

Your archive .js 您的档案.js

  Template.myPost.helpers({
       'newrow': function(newrow){
          // new row is this in your template, this contain all attributes,
          // you can return anything you want, remember that the condition 
          // if require true or false
          return ...
       },
       'myPostImages':function(){
          // return array of collection
          var model= Collection.find({}).fetch(); 
          // you can create an array in your new model 
          model.url= []; 
          return model;
       } 
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM