asp.net mvc 3 - How to check checkbox for only checked item on jquery success function -


as need check items has value true controller on jquery success function.

<script type="text/javascript">      $("#pid").change(function ()           {             $.ajax({             url: '@url.action("getcheckedchannel","channels")',             type: 'post',             data: { pid: $(this).val() },             success: function (data) {                     (var = 0; < data.length; i++)                      {                        //if (data[i].ischecked == "1") {                        var status = data[i].ischecked ? true : false;                        $(".ischeck").attr("checked", status);                       //}                      }             }       });     }); </script> 

you can write this

data[i].ischecked ? $(".ischeck").prop("checked", true) : ''; 

also consider using .prop instead of .attr set checked property


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -