2014-01-13 25 views
2

我装羊驼和羊驼,引导 地铁加羊驼 MRT添加羊驼,引导流星和羊驼形成

,并把从羊驼首页上的代码,以我的模板是这样的: 并没有什么办法可以让这行得通。我也试图不使用mrt包,把JavaScript放在不同的文件中......任何人都有线索? 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> 

回答

0

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 
    }; 
+0

Thx,这是有点它。问题是我把$(“#formxxx”)。alpaca({});在templates.js里面,它被automaticaly封装在一个像函数那样的函数中($(“#formxxx”).alpaca({}););所以它没有开始。 THX为你的帮助弗雷德里科 – ANdyCZ