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

Passing Parameters through HTML bindings (MVVM)

1 Answer 442 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 14 Dec 2012, 10:01 PM
Is it possible to use any sort of parameters in the HTML bindings with the MVVM framework? For instance ...


Assume I have a ViewModel that has two properties; Id and Points, and a function that accepts Id as a paramter.

var viewModel kendo.observable({
    Id"users/1",
    Points10,
    ReducePointsfunction(id{
        console.log(id);
    }
});
kendo.bind(document.bodyviewModel);


and I want to use one of these variables in a click data-binding.

<div data-bind="text: Id"></div >
<div data-bind="text: Points"></div >

<div data-bind="click: ReducePoints(this.Id)">Click Here</div>


Is there any possible way to do that? To use the view model's properties - or to pass parameters through the bindings?

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 18 Dec 2012, 11:30 AM
Hi Derek,

 
You can achieve the desired behavior in the following way:

ViewModel:

var viewModel = kendo.observable({
    Id: "users/1",
    Points: 10,
    ReducePoints: function(id) {
        console.log(this.get("Id"));
    }
});

Click data binding:
<div data-bind="click: ReducePoints">Click Here</div>

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
Derek
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or