新手流星问题...
我的代码与此大致相似:
<template name="fancy-button">
<p>This is a fancy button that I use in several places!</p>
<input type="button" class="very-fancy" value="Click Me!" />
</template>
<template name="homepage">
{{> fancy-button}}
// here, I want the button to bring up my "stats" page (go, iron-router, go)
</template>
<template name="stats-page">
{{> fancy-button}}
// here, I want the button to show an alert
</template>
问题:在“homepage”和“stats-page”中,有没有办法知道用户是否点击了“fancy-button”中的按钮?
(或者这只是在流星中实现事物的错误方法?)
非常感谢,@paul!我去了这样的事情:
<template name="fancyButton">
<p>This is a fancy button that I use in several places!</p>
<input type="button" class="veryFancy" value="Click Me!" />
</template>
<template name="homePage">
{{> fancyButton}}
{{respondToFancyButton}}
<!-- here, I want the button to bring up my "stats" page (go, iron-router, go) -->
</template>
<template name="statsPage">
{{> fancyButton}}
{{respondToFancyButton}}
<!-- here, I want the button to show an alert -->
</template>
然后,在我的 JavaScript 客户端代码中:
Session.set("fancyButtonMonitor", 0);
Template.fancyButton.events({
'click .veryFancy': function(theEvent, theTemplate) {
Session.set("fancyButtonMonitor", 1);
}
});
Template.homepage.respondToFancyButton = function () {
if (Session.get("fancyButtonMonitor") == 1) {
Session.set("fancyButtonMonitor", 0);
Router.go('stats');
}
return null;
};
Template.statsPage.respondToFancyButton = function () {
if (Session.get("fancyButtonMonitor") == 1) {
Session.set("fancyButtonMonitor", 0);
Router.go('alert');
}
return null;
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)