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

cannot bind to click event

2 Answers 801 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Veteran
Neeraj asked on 23 Sep 2017, 06:42 AM

Hello,
            I have that has a function save. and 2 external templates files

 

PricingViewModel = kendo.observable({
        savePrice: function(e) {
            debugger;
        },
        Item: {
        Items: ModelData,
        SavePricing: function(e){
        }
});

 

 

The PricingViewModel is bind to template . there is another template in which the data source is not part of this . have ajax function that calls data and binds to    template has a button which want  bind to  () or how can do that?
          also tried kendo.bind() that worked. It gets bind to normal javascript function outside  but in that  get e.data !!

 

2 Answers, 1 is accepted

Sort by
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 24 Sep 2017, 07:44 AM
there is a property inside Items (which as ModelData) have a  have  that button with SavePricing function and also tried         I get error:

Uncaught TypeError: n is not a function

          How can bind inside element button with outer functions? like(savePricing() and () )
0
Veselin Tsvetanov
Telerik team
answered on 26 Sep 2017, 09:56 AM
Hi Neeraj,

As far as I can understand, you are trying to bind a click handler of a button, which is placed in a template to a function, which is defined in the ViewModel (not defined in an item from the Items collection).

If this is the case, the above could be implemented in the template in the following way:
<script type="text/x-kendo-template" id="myTemplate">
    <li>ID: #: ProductID #; Name: #: ProductName #
    <input type="button" value="Click me" data-bind="events: { click: savePrice }" >
  </li>
</script>

Here you could find a simple Dojo, implementing the above suggestion.

Here you could find a bit more information on events binding in MVVM.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
MVVM
Asked by
Neeraj
Top achievements
Rank 1
Veteran
Answers by
Neeraj
Top achievements
Rank 1
Veteran
Veselin Tsvetanov
Telerik team
Share this question
or