简体   繁体   English

为什么引导面板的位置在 Meteorjs 上是随机的?

[英]Why the position of bootstrap panels is random on Meteorjs?

I created a project with Meteorjs and Bootstrap 3.我用 Meteorjs 和 Bootstrap 3 创建了一个项目。

In this project, I can add dynamically bootstrap panels (or modals) to the Home page.在这个项目中,我可以将动态引导面板(或模态)添加到主页。

What bothers me is the fact that the position of theses panels (or modals) is random, I would like them to be organized.困扰我的是这些面板(或模态)的位置是随机的,我希望它们被组织起来。 Eg: when the screen of computer is medium, I want 3 panels (or modals) in each column.例如:当计算机屏幕为中等时,我希望每列中有 3 个面板(或模态)。

Would you have an idea on how to do that?你会知道如何做到这一点吗?

The code is:代码是:

<template name="home">
{{> navigation}}
<div class="container-fluid lov">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
 {{#each positions}}
  {{> position}}
  {{/each}}
 </div>
</div>  
</div>
</template>

And this is the JavaScript of this template:这是这个模板的 JavaScript:

Template.home.events ({
'dblclick .lov': function (e, tmpl) {
    e.preventDefault();
    e.stopPropagation();

 if(e.target.className === 'container-fluid lov'){
     var id = Positions.insert({ name:'Clique here to change the title', domaine:'ici tu ecris ton text en gros',footername:'le nom de pays et la ville si tu veux'});
     Session.set('editing_table',id);

    }
}   

});

This is the collection:这是合集:

Positions = new Meteor.Collection('positions');

This one is the code of position template that allow us to create our panel:这是允许我们创建面板的位置模板代码:

<template name="position">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">


<div class="panel panel-default" id="{{_id}}"  style="position:absolute;left:{{left}};top:{{top}}; width:350px">
  <div class="panel-heading">
  {{#if hadanata3ou}}
        <a  class="close" data-dismiss="modal">x</a>{{/if}}
        {{#if editing_tablename}} 
          <input class="input input-medium tablename" value="{{name}}" type="text" />
        {{else}}
        <h6 class="tablename">{{name}}</h6>
        {{/if}}
  <!--   <h3 class="panel-title">Panel title</h3> -->
  </div>
  <div class="panel-body">
    <div id="{{_id}}">
         {{#if editing_field}}

        <textarea class="input input-lg efield" name="efield" type="text">
        {{domaine}}
        </textarea>
         {{else}}
          <span>
          {{domaine}}
         </span>
         {{/if}}
       </div>
  </div>
  <div class="panel-footer">
    {{#if editing_footer}}
          <input class="input input-medium footer" value="{{footername}}" type="text" />
        {{else}}
        <p class="muted">{{footername}}</p>
        {{/if}}
      </div>
  </div>
</div>
</div>
</template>

I'll be honest, I don't know a whole lot about meteorjs templating, but I can show you how the Bootstrap grid system works for rendering different amounts of panels based on the size of the view.老实说,我对meteorjs模板meteorjs ,但我可以向您展示Bootstrap网格系统如何根据视图的大小渲染不同数量的面板。

Bootstrap uses 4 different sizes: Bootstrap 使用 4 种不同的大小:

  • Large lg (Desktop)大型lg (台式机)
  • Medium md (Landscape Tablet)中等md (横向平板电脑)
  • Small sm (Portrait Tablet)sm (人像平板)
  • Extra Small xs (Mobile)超小xs (移动)

And using the classes .visible-SIZE and .hidden-SIZE , you can control what elements are shown/rendered at what sizes.而使用类.visible-SIZE.hidden-SIZE ,你可以控制哪些元素显示/什么尺寸呈现。 For example:例如:

<div class="container-fluid">
  <div class="row visible-lg visible-md hidden-sm hidden-xs" >
    <div class="col-lg-4 col-md-4">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4><span class="hidden-lg visible-md">Panel One - Medium</span> <span class="hiddn-md visible-lg">Panel One - Large</span></h4>
        </div>
      </div>
    </div>
    <div class="col-lg-4 col-md-4">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4><span class="hidden-lg visible-md">Panel Two - Medium</span> <span class="hiddn-md visible-lg">Panel Two - Large</span></h4>
        </div>
      </div>
    </div>
    <div class="col-lg-4 col-md-4">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4><span class="hidden-lg visible-md">Panel Three - Medium</span> <span class="hiddn-md visible-lg">Panel Three - Large</span></h4>
        </div>
      </div>
    </div>
  </div>
  <div class="row hidden-lg hidden-md visible-sm visible-xs">
    <div class="col-sm-6 col-xs-6">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4><span class="hidden-sm visible-xs">Panel One - Extra Small</span> <span class="hiddn-xs visible-sm">Panel One - Small</span></h4>
        </div>
      </div>
    </div>
    <div class="col-sm-6 col-xs-6">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4><span class="hidden-sm visible-xs">Panel Two - Extra Small</span> <span class="hiddn-xs visible-sm">Panel Two - Small</span></h4>
        </div>
      </div>
    </div>
  </div>
</div>

This code renders a row of .panel panel-default <div> elements.此代码呈现一行.panel panel-default <div>元素。 When the view is md or lg , it renders 3 <div> 's, each with the class col-md-4 and col-lg-4 .当视图是mdlg ,它呈现 3 个<div> ,每个都有col-md-4col-lg-4 The total amount of columns you can have is 12, and a class with col-*-4 takes up 4 of those 12 slots.您可以拥有的总列数是 12,一个带有col-*-4占用了这 12 个插槽中的 4 个。 Therefore, 3 * 4 is 12, or 1 complete row.因此,3 * 4 是 12,或 1 个完整的行。 Same with 2 * 6 for the col-sm-6 and col-xs-6 .col-sm-6col-xs-6 2 * 6 相同。

In your meterojs templates, you need to decide how to use these classes to render the correct amount of columns.在您的meterojs模板中,您需要决定如何使用这些类来呈现正确数量的列。 It's not too difficult, but spend some time playing with it to get the layout you want.这不是太难,但花一些时间玩它以获得您想要的布局。 If you want to see the test layout in effect, check this link:如果您想查看有效的测试布局,请查看此链接:

Bootply引导

And try resizing your browser window.并尝试调整浏览器窗口的大小。

Hope that can provide you some insight into Bootstrap 's grid layout, and how to render different columns depending on the size of your browser.希望可以让您深入了解Bootstrap的网格布局,以及如何根据浏览器的大小呈现不同的列。

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

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