【发布时间】:2016-01-05 12:59:47
【问题描述】:
我有一个主模板,还有两个通过 (Iron) 路由显示:
<template name="main">
<div id="templateMain" name="templateMain">
<a href="nfnoscar">The Legend of NFN Oscar</a>
<br/>
<a href="nfnoscarsdonut">NFN Oscar's donut</a>
</div>
</template>
<template name="nfnoscar">
<h1>The True Story of NFN Oscar</h1>
<h2 class="monospaceboldsmallcap">Come and Listen to a Story About a Man without a first Name</h2>
<p>Many people wonder how it can be that NFN (No First Name) Oscar Herrera does not have a first name.</p>
<p>Finally, the secret of his birth name and its subsequent alteration can be revealed.</p>
. . .
挑战是我想在显示其他模板时从主模板中隐藏两个链接/锚标记。我有一个“隐藏” CSS 类,它隐藏了一个附加了该类的元素。
我可以利用什么事件(不是双关语)来完成这个?
我试过了:
Template.nfnoscar.onRendered({
$('#templateMain').addClass('hide');
});
Template.nfnoscarsdonut.onRendered({
$('#templateMain').addClass('hide');
});
Template.main.onRendered({
$('#templateMain').removeClass('hide');
});
...但是我在编译时收到错误消息;无论如何,我认为我不能从其他模板中引用主模板中的元素(或者这可能是我的全部问题)。我在控制台/命令提示符(Windows 7)中看到的错误是:
=> Errors prevented startup:
While processing files with ecmascript (for target web.browser):
platypus.js:8:6: platypus.js: Unexpected token (8:6)
While processing files with ecmascript (for target os.windows.x86_32):
platypus.js:8:6: platypus.js: Unexpected token (8:6)
=> Your application has errors. Waiting for file change.
那么在路由到它们时需要更改/如何隐藏这些初始链接?
这是我的整个 *.js 文件:
Router.route('/');
Router.route('/nfnoscar');
Router.route('/nfnoscarsdonut');
if (Meteor.isClient) {
Template.nfnoscar.onRendered({
$('#templateMain').addClass('hide');
});
Template.nfnoscarsdonut.onRendered({
$('#templateMain').addClass('hide');
});
Template.main.onRendered({
$('#templateMain').removeClass('hide');
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
所以抱怨的 line:character (8:6) 是这里“$”后面的“(”:
Template.nfnoscar.onRendered({
$('#templateMain').addClass('hide');
});
【问题讨论】:
标签: javascript jquery templates meteor meteor-blaze