Bootstraps ICheck no puede escuchar el evento cambiado
Dec 15 2020
Tengo este código Jquery para actualizar las radios en función de si se ha verificado una radio. Sin embargo, esto no dispara.
Código
this.init = function() {
$.ajax({ "url": "/cms/api/task_management/init", "contentType": "application/json", "dataType": "json", "type": "POST" }).done(function(map) { if ($("#title").val() || $("#problemCls").val() || $("#targetFunc").val() || $("#status").val() || $("#priority").val()) {
search();
} else {
callBackInit(map);
}
}).fail(failCallback);
$("input[type='radio']").on("ifChanged", function (event) { if ($("#display-method-unique").prop("checked")) {
renderDataTable(self.taskManagementList);
} else {
renderDataTable(self.allDataList);
}
}).iCheck({
radioClass: 'iradio_flat-green'
});
HTML
<div class="row">
<div class="col-md-4 col-sm-12 col-xs-12">
<div class="radio">
<input type="radio" name="display-method" id="display-method-unique" class="flat"><label for="display-method-unique">Doing</label>
<input type="radio" name="display-method" id="display-method-all" class="flat"><label for="display-method-all">End</label>
</div>
</div>
</div>
También intenté vincularme a la función de clic y cambiar la función. Pero el evento de cambio no se puede escuchar. Sin embargo, ninguno parece funcionar. Todo funciona bien cuando no agrego el script Icheck.js.
¿Alguien sabe cómo conectarse a un evento cambiado desde la clase bootstraps Icheckhelper?
Respuestas
1 XinLiu Dec 16 2020 at 07:18
Encontré una solución útil, ya que se respondió correctamente desde el foro de github: lea de este hilo y ¿Cómo manejar el evento de radio cuando se usa iCheck-helper?
Luego cambié mi código. El problema se ha resuelto.
$("input[name='display-method']").iCheck({radioClass: 'iradio_flat-green'}); this.init = function() { $.ajax({
"url": "/cms/api/task_management/init",
"contentType": "application/json",
"dataType": "json",
"type": "POST"
}).done(function(map) {
if ($("#title").val() || $("#problemCls").val() || $("#targetFunc").val() || $("#status").val() || $("#priority").val()) { search(); } else { callBackInit(map); } $("input[name='display-method']").on("ifCreated ifClicked ifChanged ifChecked ifUnchecked ifDisabled ifEnabled ifDestroyed check", function (event) {
if ($("#display-method-unique").prop("checked")) {
renderDataTable(self.taskManagementList);
} else {
renderDataTable(self.allDataList);
}
});
}).fail(failCallback);
};