我安装了羊驼和羊驼引导
mrt add alpaca
mrt add alpaca-bootstrap
并将代码从羊驼首页放到我的模板中,如下所示。
而且我无法使它工作。我也尝试过不使用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>
最佳答案
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
};