开关工作在双击| ROR



我使用一个开关(类似于切换按钮)向用户显示一些数据。但是这个开关只在双击时有效,而不是一次点击。

下面是.js文件中的代码-

var integrations = {
init: function() {
$("input[type='checkbox'].integration").bootstrapSwitch();
$("input[type='checkbox'].integration").on('switchChange.bootstrapSwitch', function(e, state) {
$(this).siblings('.bootstrap-switch-label').click();
var val = $("input[type='checkbox'].integration").val()
if (val === 'true')
$(this).prop( "checked", true);
else
$(this).prop( "checked", false);
});
this.jiraService = w.service.get('jira').init();
this.jiraService.initEvents();
if (w.Clipboard) {
new w.Clipboard(".copy.tooltip-right");
}
}
};

有谁知道如何使其工作为单一点击?请帮助!

你可以通过注释下面的行来检查,这可能是标签也使开关点击。

$(this).siblings('.bootstrap-switch-label').click(); 

如果有人还在寻找解决方案,试试这个-

if ($(this).on(".bootstrap-switch-handle-on bootstrap-switch-success").click())
$(this).prop( "checked", true);
else
$(this).prop( "checked", false);

更改if条件对我有效。