Issue binding a click event handler within a template item

3 posts, 0 answers
  1. London TIO
    London TIO avatar
    3 posts
    Member since:
    Aug 2013

    Posted 18 Mar 2014 Link to this post

    Hello, I'm trying to bind an array of primitive objects to an un-ordered list using the example from the getting started documentation here:

    I'd like to add a button along side each list item that, when clicked, removes the item from the list.

    When I run the example above without the addition of a click event handler, everything works fine as the below link shows:

    However, when I add a click event handler to the same span, or even a neighboring span element as below...

    I get the following error in Chrome's console:

    Uncaught TypeError: Object Coffee has no method 'get'

    and the rest of the list fails to render correctly. Is this a bug or am I binding in an unusual way?

    Thanks in advance, Sam.
  2. London TIO
    London TIO avatar
    3 posts
    Member since:
    Aug 2013

    Posted 19 Mar 2014 in reply to London TIO Link to this post


    I've realised that I'm actually binding the click event to a non-existent function i.e. 'viewModel.products.handleClick, where 'products' is the source of the template, in actual fact I need to target 'viewModel.handleClick'.

    So I'll change my question, is there anyway to point to an event handler that exists outside of the 'source' binding such as:

        <span data-bind="text: this, click: viewModel.handleClick"></span>
  3. Alexander Valchev
    Alexander Valchev avatar
    2873 posts

    Posted 20 Mar 2014 Link to this post


    The scenario which you are trying to implement is not supported. The reason is that Kendo MVVM does not wrap the primitive values into Observable object. Primitive objects does not have a parent method (Observable Object has) and as a result the click binding cannot be resolved.

    In case you would like to bind the click event, please consider source binding the UI to array with objects.

    Alexander Valchev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top