【发布时间】:2015-03-16 02:54:05
【问题描述】:
我尝试创建一个可重复使用的确认框,但我不确定如何以流星的方式实现它。
我有一个确认框的模板。文本和按钮值应该是动态的。
<template name="confirm">
{{#if show}}
{{text}}
<button class="cancel">cancel</button>
<button class="confirm">{{action}}</button>
{{/if}}
</template>
我有一个带有删除按钮的用户模板。
<template name="user">
<h1>{{name}}</h1>
<button class="delete">delete user</button>
</template>
在应用程序模板中,我显示用户列表并呈现确认模板。
<template app="app">
{{#each user}}
{{> user}}
{{/each}}
{{> confirm}}
</tempalte>
现在,当我单击用户项的删除按钮时,我想显示确认框。
Template.confirm.helpers({
text: function(){
return Session.get('confirmText');
},
action: function(){
return Session.get('confirmAction');
},
show: function(){
return Session.get('showConfirm');
},
});
Template.user.events({
'click .delete': function(){
Session.set('confirmAction', 'delete');
Session.set('confirmText', 'Are you sure?');
Session.set('showConfirm', true);
}
});
我的确认框按原样显示,但我如何触发从确认框中删除用户?
我是否走在正确的轨道上?我尝试在每个用户模板中呈现一个确认模板,但一次应该只有一个活动确认框。
【问题讨论】:
标签: javascript templates meteor meteor-blaze