Data directives and click event?

3 posts, 1 answers
  1. Phil H.
    Phil H. avatar
    88 posts
    Member since:
    Nov 2008

    Posted 24 Jun 2014 Link to this post

    Hi:

    I would like to use data- directives but click is not working:
    <div class='k-button' data-bind='click: newProduct'><span class="k-icon k-i-plus"></span> New</div>
    <script type="text/javascript">
        function newProduct(evt) {
            alert(evt.event.target.tagName);
        }
    </script>
    Phil

  2. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 25 Jun 2014 Link to this post

    Hi Phil,

    Data binding works only when the HTML is bound to a ViewModel via kendo.bind method. For more information and code samples please check this article.

    Regards,
    Alexander Valchev
    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
  4. Phil H.
    Phil H. avatar
    88 posts
    Member since:
    Nov 2008

    Posted 25 Jun 2014 in reply to Alexander Valchev Link to this post

    Hi All:
    Cool thanks, this is my sample...
    <div id='newProdView'>
        <div class='k-button' data-bind='click: newProduct'><span class='k-icon k-i-plus'></span> New</div>
    </div>
    <script type="text/javascript">
        var newProdViewModel = kendo.observable({
            newProduct: function (vm) {
                // vm is the view model
                alert(vm.target.innerText);
            }
        });
        kendo.bind($("#newProdView"), newProdViewModel);
    </script>
    Phil
Back to Top