ListView of switches

2 posts, 0 answers
  1. Walid
    Walid avatar
    19 posts
    Member since:
    May 2013

    Posted 11 Jul 2013 Link to this post

    Hello,
    I have a basic listview, bound to a dataSource(JS array of objects), with an item template that contains a switch, 
    Ex:
    <script id="listItemTemplate" type="text/x-kendo-template">
           <div>
                <a> #=name# </a>
                <input type="checkbox" #if(data.selected) { # checked #}# data-role="switch" data-bind="checked: selected" />
           </div>
    </script>

    The list is rendered corectly, however the switch data binding does not seem to be working. 
    Had to specify the [#if(data.selected) { # checked #}#], otherwise it woudn't have set the checked state corectly.
    I expect 2 way binding. Thiking this should work.
    Am i doing something wrong?

    Regards
  2. Petyo
    Admin
    Petyo avatar
    2438 posts

    Posted 12 Jul 2013 Link to this post

    Hi Walid,

    In order for the two-way binding to work, you will have to employ the MVVM pattern. Please check this example

    Regards,
    Petyo
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
Back to Top