This is a migrated thread and some comments may be shown as answers.

Data directives and click event?

2 Answers 38 Views
Button
This is a migrated thread and some comments may be shown as answers.
Phil H.
Top achievements
Rank 2
Phil H. asked on 24 Jun 2014, 11:19 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 25 Jun 2014, 11:07 AM
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!
 
0
Phil H.
Top achievements
Rank 2
answered on 26 Jun 2014, 12:15 AM
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
Tags
Button
Asked by
Phil H.
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Phil H.
Top achievements
Rank 2
Share this question
or