Data directives and click event within a View?

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

    Posted 28 Jun 2014 Link to this post

    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
  2. Answer
    Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 01 Jul 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Phil H.
    Phil H. avatar
    88 posts
    Member since:
    Nov 2008

    Posted 03 Jul 2014 in reply to Petyo Link to this post

    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
  5. Phil H.
    Phil H. avatar
    88 posts
    Member since:
    Nov 2008

    Posted 04 Jul 2014 in reply to Phil H. Link to this post

    Hi:
    Solved:
    var newTemplate = new kendo.View('newButton-template', { model: newProdViewModel });
    newTemplate.render('#newProdView');
    Phil
Back to Top
Kendo UI is VS 2017 Ready