我对meteorjs和一般的网络开发都很陌生。
我有两个模板,一个放在另一个模板中。是否有可能在模板中获取一个实例,以便我可以在其中执行一些jquery操作?
<template name="customTemplate">
<div>
<button class="start">StartUpload</button>
</div>
</template>
.....
<template name="postItem">
<div class="container">
<h1>POST!!!!</h1>
{{> customTemplate }}
<button class="buttonPost">Post new item</button>
</div>
</template>
Template.postItem.events({
"click .buttonPost": function(e, template) {
// I'd like to get the instance of customTemplate here so I can
// manually click the "start" button
}
});
答案 0 :(得分:1)
使用模板实例:
这是一个例子:
HTML:
<body>
<h1>Welcome to Meteor!</h1>
{{> hello}}
</body>
<template name="hello">
<button class="sayHello">Click Me</button>
{{> sayGoodbye}}
</template>
<template name="sayGoodbye">
<button class="goodbye">
Goodbye
</button>
</template>
JS
Template.sayGoodbye.events({
"click .goodbye":function(evetnt){
console.log("sayGoodbye is clicked");
}
});
Template.hello.events({
"click .sayHello":function(event){
Template.instance("sayGoodbye").$(".goodbye").click();
}
});
这是一个普遍的例子。在你的场合:
Template.postItem.events({
"click .buttonPost": function(e, template) {
// I'd like to get the instance of customTemplate here so I can
// manually click the "start" button
Template.instance("customTemplate").$(".start").click();
}
});