本文介绍了流星和羊驼形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了羊驼和羊驼 - 引导程序
mrt add alpaca
mrt add alpaca-bootstrap

I installed alpaca and alpaca-bootstrapmrt add alpacamrt add alpaca-bootstrap

并将alpaca主页的代码放到我的像这样的模板:
,我无法让它工作。我也尝试过不使用mrt包,把javascript放在不同的文件中......任何人都有线索? Thx

and put the code from alpaca homepage to my template like this:and there is no way i can make it work. I also tried not to use mrt package, put javascript in different file... Anyone has a clue? Thx

<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>


推荐答案

Javascript代码不属于模板。您应该将该代码放在Template.created事件中()。

Javascript code does not belong in templates. You should instead be placing that code in a "Template.created" event (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 
  };

这篇关于流星和羊驼形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:07