【问题标题】:Meteor and Alpaca forms流星和羊驼的形式
【发布时间】:2014-02-01 12:11:10
【问题描述】:

我安装了 alpaca 和 alpaca-bootstrap

mrt add alpaca
mrt add alpaca-bootstrap

然后将 alpaca 主页中的代码放到我的模板中,如下所示。 而且我无法让它发挥作用。我也尝试不使用mrt包,将javascript放在不同的文件中......有人有线索吗?谢谢

<template name="templates">
    <div id="content">
      <div class="container">
        <div class="row">
          <!--main content-->
          <div class="col-md-12">
            <h2 class="title-divider"><span>Templates<span class="de-em"></span></span> <small>What & who makes us tick!</small></h2>
            <div id="formxxx"></div>

            <script type="text/javascript">
              $(function() {
                $("#formxxx").alpaca({
                  "schema": {
                    "title": "User Feedback",
                    "description": "What do you think about Alpaca?",
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string",
                        "title": "Name"
                      },
                      "ranking": {
                        "type": "string",
                        "title": "Ranking",
                        "enum": ['excellent', 'not too shabby', 'alpaca built my hotrod']
                      }
                    }
                  }
                });
              });
            </script>
          </div>
        </div>
      </div>
    </div>
</template>

【问题讨论】:

    标签: jquery meteor twitter-bootstrap-3 alpacajs


    【解决方案1】:

    Javascript 代码不属于模板。您应该将该代码放在“Template.created”事件 (http://docs.meteor.com/#template_created) 中。

      Template.templates.created = function() {
        $("#formxxx").alpaca({
          "schema": {
            "title": "User Feedback",
            "description": "What do you think about Alpaca?",
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "title": "Name"
              },
              "ranking": {
                "type": "string",
                "title": "Ranking",
                "enum": ['excellent', 'not too shabby', 'alpaca built my hotrod']
              }
            }
          }
        });
      };
    
      Template.templates.destroyed = function() {
        $("#formxxx").alpaca().destroy(); // never used alpaca so it might not work, but you should destroy any event listeners when the template gets destroyed 
      };
    

    【讨论】:

    • 谢谢,就是这样。问题是我把 $("#formxxx").alpaca({});在 templates.js 中,它被自动包装在一个函数中,比如 function($("#formxxx").alpaca({}););所以它没有开始。感谢您的帮助弗雷德里科
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2016-11-04
    相关资源
    最近更新 更多