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

Data directives and click event within a View?

3 Answers 84 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 28 Jun 2014, 01:48 PM
Hi:

I am experiencing a jQuery error: Object doesn't support property or method 'apply', when I click on the button:
<script id='newButton-template' type='text/x-kendo-template'>
  <button class='k-button' data-bind='click: newProduct'><span class='k-icon k-i-plus'></span> New</button>
</script>
<div id='newProdView'>
</div>
<script type="text/javascript">
  var newProdViewModel = kendo.observable({
     newProduct: function (vm) {
       // vm is the view model
       alert(vm.target.innerText);
     }
  });
  var newTemplate = new kendo.View('newButton-template');
  newTemplate.render("#newProdView", newProdViewModel);
</script>

Phil

3 Answers, 1 is accepted

Sort by
0
Accepted
Petyo
Telerik team
answered on 01 Jul 2014, 11:24 AM
Hi Phil,

Given, you are passing the view model at the render call - it should be passed in the view constructor. Please check the respective help article (which also features several code samples) regarding SPA/MVVM integration and MVVM bound view.

Regards,
Petyo
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 04 Jul 2014, 01:59 AM
Hi Petyo:

Thanks, this works.
<script id='newButton-template' type='text/x-kendo-template'>
    <button class='k-button' data-bind='click: newProduct'><span class='k-icon k-i-plus'></span> New</button>
</script>
<div id='newProdView'>
</div>
<script type="text/javascript">
    var newProdViewModel = kendo.observable({
        newProduct: function (vm) {
            // vm is the view model
            alert(vm.target.innerText);
        }
    });
    var newTemplate = new kendo.View('newButton-template', { model: newProdViewModel });
    newTemplate.render('#newProdView');
</script>

Phil
0
Phil H.
Top achievements
Rank 2
answered on 04 Jul 2014, 01:11 PM
Hi:
Solved:
var newTemplate = new kendo.View('newButton-template', { model: newProdViewModel });
newTemplate.render('#newProdView');
Phil
Tags
Button
Asked by
Phil H.
Top achievements
Rank 2
Answers by
Petyo
Telerik team
Phil H.
Top achievements
Rank 2
Share this question
or