Kendo Template check box not firing click event

爷,独闯天下 提交于 2019-12-10 23:59:07

问题


I have used Kendo Template as follows:

<script type="text/javascript" src="@Url.Content("~/Scripts/Module/Analysis/CreateMaintainAnalysis.js")"></script>
    <script type="text/x-kendo-template" id="Modeltemplate">
        <div class="section group fr">
            <div class="col span_2_of_12">
                #if(ACTIVE_MODELS_COUNT > 0){# <input class="ModelCheckBox"  type="checkbox"  checked/>#} else {# <input class="ModelCheckBox" type="checkbox" unchecked/>  #}#
            </div>
            <div class="col span_4_of_12"><label>#:MODEL#</label></div>
        </div>
      </script>

and I want to write click event on CheckBox Click as follows:

$("#ModelListView").kendoListView({
    template: kendo.template($("#Modeltemplate").html())
});

     $(".ModelCheckBox").click(function () {
        if (this.checked) { alert("Checked"); }
         });

回答1:


Most probably, the click handler is attached too early, before the ListView is data bound, so there are still no checkboxes rendered. You have two options -

  1. Execute the code below in the dataBound event of the ListView.

    http://docs.telerik.com/kendo-ui/api/javascript/ui/listview#events-dataBound

    $(".ModelCheckBox").click(function () {
       if (this.checked) { alert("Checked"); }
    });
    
  2. Use a delegate that is attached to the ListView <div>

    $("#ModelListView").on("click", ".ModelCheckBox", function () {
       if (this.checked) { alert("Checked"); }
    });
    


来源:https://stackoverflow.com/questions/38724162/kendo-template-check-box-not-firing-click-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!