Reputation: 2589
When an event happens in a template, I want to do something in another template.
this is my code:
client html:
<body> Navigation: {{> navigation}} ======================================================= Body: {{> body}} </body> <template name="navigation"> <input type="button" value="MenuBtn" /> </template> <template name="body"> {{content}} </template>
JavaScript:
Template.navigation.events({ 'click' : function (e) { //Nothing happened in {{body}} Template.body.content = function(){ // i want to do something... like query database // maybe, just a example : return peple.find({"name":e.currenTarget.value}); return "hello"; }; } });
Any idea about what I am doing wrong?
Upvotes: 2
Views: 422
Reputation: 75945
Use handlebars to pass data to the template so the templating system knows when to redraw the html
Client JS
Template.body.content = function() {
return Session.get("content") || "Hi there, click the button"
};
Template.navigation.events({
'click' : function () {
alert("1");// it's normal
Session.set("content", "<h1>HELLO!!!! '+ people.findOne({"name":e.currenTarget.value}).name || " unregisterd person" + '</h1>");
alert("2");//it's normal
}
});
I also assume you're going to do something HTMLey and you don't want it to be escaped so make sure you use:
<template name="body">
{{{content}}}
</template>
Upvotes: 3