在模板中处理开关盒的最佳方法是什么(例如:具有 4 种可能状态的按钮)?将 html 拉到 helper 中似乎是错误的,但将逻辑放入模板中感觉同样糟糕......
编辑:
如您所见,将 html 放在帮助程序中远非理想,但更改类、标记名、属性和内容会使模板完全不可读。
Template.nextMeetup.helpers({
rsvpButton: function(rsvp) {
var button;
switch(rsvp){
case 'yes':
button = '<a ' + this.event_url + 'class="rsvp btn btn-success pull-right" title="visit event page" target="_blank"><i class="icon-check"></i> I\'m Attending</a>';
break;
case 'maybe':
button = '<a ' + this.event_url + 'class="rsvp btn btn-warning pull-right" title="visit event page" target="_blank"><i class="icon-warning-sign"></i> I might go</a>';
break;
case 'no':
button = '<a ' + this.event_url + 'class="rsvp btn btn-danger pull-right" title="visit event page" target="_blank"><i class="icon-remove"></i> I\'m not going</a>';
break;
case 'none':
button = '<a ' + this.event_url + 'class="rsvp btn btn-inverse pull-right" title="visit event page" target="_blank"><i class="icon-spinner"></i> I havn\'t decided</a>';
break;
default:
button = '<button class="rsvp signIn btn btn-disabled pull-right">Sign in to RSVP</button>';
}
return new Handlebars.SafeString(button);
}
});