我有一个附加到复选框的事件处理程序。我正在使用引导开关http://www.bootstrap-switch.org/ http://www.bootstrap-switch.org/
我试图将 true 或 false 的状态值获取到变量中,以便我可以将其设置为会话值。
当状态发生变化时,我可以获得 true 或 false 值(如渲染代码中所示)。但是,我想在事件中获得这个值。请检查我的 x 变量。
客户端.js
Template.myTemplate.rendered = function () {
$('input[name="questions"]').bootstrapSwitch('state', true, true);
$('input[name="questions"]').on('switchChange.bootstrapSwitch', function(event, state) {
console.log(state); // true | false
});
html:
<template name="myTemplate">
<div class="row">
<input type="checkbox" name="questions" unchecked> Hobby?
</div>
<div class="row">
<input type="checkbox" name="questions" unchecked> Writer?
</div>
我正在尝试获取打印出来的值console.log(state)
在渲染的代码中放入我的事件中的变量中,以便我可以将会话的值设置为 true 或 false。
Template.myTemplate.events({
'click input': function(event) {
var x = $(this).is(":checked").val();
Session.set("statevalue", x);
console.log(Session.get("statevalue")); // this is not printing out anything
}
});