Hamad
Hamad

Reputation: 70

how to pass data-bind value as parameter when calling breeze function

I want to pass a data-bind value as function parameter.

Here is sample code:

<data-bind="click: function (data) { myFunction('param1', data) }">

this is my view model

var vm = {
Category: ko.observableArray(),
Product: ko.observableArray(),
CatID: ko.observable("113"),
save: saveChanges,
Filter: FilterProduct,
};

CatID is an observable so there are some functions who change the CatID when they are called. and i want to pass this CatID as a parameter when specific button clicked.

Please help how can i do this.

Upvotes: 2

Views: 3359

Answers (1)

G&#244;T&#244;
G&#244;T&#244;

Reputation: 8053

You can pass the observable in the data-bind like this

<button data-bind="click: myFunction(CatID)">Test Click</button>

And define your function in your ViewModel:

var vm = {
        Category: ko.observableArray(),
        Product: ko.observableArray(),
        CatID: ko.observable("113"),
        myFunction: function (obs) {
            alert(obs());
        }
    };

I have created an example here: http://jsfiddle.net/nyothecat/QruPg/

Upvotes: 5

Related Questions