javascript - 试图了解 meteor

标签 javascript jquery html css meteor

<head>
  <title>bubblePop</title>
</head>

<body>


  <center>{{> hello}}<center>
</body>

<template name="hello">
  <h1>Bubble Pop!!!!</h1>
  {{greeting}}

</template>

我明白 Handlebars {{> hello}} 是怎么回事,基本上这样你就可以在任何地方插入 {{> hello}},它与模板中的一样。但我正在尝试使用 javascript 在我的 meteor 应用程序上制作一张大 table 。如何将我的代码放入 Handlebars 中?我可以使用 <template> 吗?在我的 JS 文件中?我的其余代码有点困惑: JS:

if(Meteor.isClient) {
  Meteor.startup(function (){
    $(document).ready(function(){
    var el;
    for(var i=1; i<=64; i++){
        el = document.createElement('div');
        $(el).addClass('button');
        $(el).on('click', function(){
            $(this).addClass('removed');
        });
        $('#container').append(el);
    }
});


  })
<template name="bubbles">


  </template>
  Template.hello.greeting = function () {
    }


  Template.hello.events({
    'click input' : function () {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

CSS:

#container {
    width: 440px;
    max-width: 440px;
}
#container > .button {
    display: inline-block;
    width: 50px;
    height: 50px;
    background-image: url('http://placehold.it/50x50');
    margin-right: 5px;
    margin-bottom: 5px;
    opacity: 0.85;
    transition: all 0.07s ease-in-out;
    -moz-transition: all 0.07s ease-in-out;
    -webkit-transition: all 0.07s ease-in-out;
    cursor: pointer;
}
#container > .button:hover {
    opacity: 1;    
}
#container > .button.removed {
    background-image: none;
}

如何让所有这些按钮都出现?有些东西我只是不明白

最佳答案

您正在尝试将命令式编程技术应用于响应式范例。

当数据更改时,模板会使用更新后的数据隐式重新呈现。

尝试在 handlebars 中创建一个简单的循环,并将表格绑定(bind)到一个集合。然后,您可以通过集合(或游标)控制行数或行的顺序。

请记住,如果将模板绑定(bind)到文档,则模板中的this 就是文档。因此,您可以根据方法或成员显示/隐藏按钮。例如。 {{getFirstName}} 就像说 my_document.getFirstName()

<table id="comments">
    <tr>
        <th>One</th>
        <th>Two</th>
    </tr>
    {{#each comments}}
        <tr>
            <td>{{one}}</td>
            <td>{{two}}</td>
        </tr>
    {{/each}}
</table>

http://handlebarsjs.com/

关于javascript - 试图了解 meteor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20590846/

相关文章:

javascript - 在html按钮onclick中打开js文件

javascript - 点击事件不适用于 anchor 标记

javascript - 从特定行加载聊天室.html文档

javascript - CMS 中的响应图像

javascript - 我可以使用 JavaScript/jQuery 捕获当前/所有选项卡 URL 还是需要制作一个插件?

html - 垂直居中的元素在顶部留下空白空间

javascript - 使用 setState 的 react-native 更新对象

javascript - addEventListener onerror 和错误事件不起作用

javascript - 使用jquery向页面链接添加参数

html - IE7、8、9 无法正确读取媒体查询。