jquery - MVC4 Knockout data-bind click event not firing -
i getting started knockout , having issue click event not firing.
the above not firing getwaiters function. not sure doing wrong or missing.
tia
i have following html:
<h2>create</h2> <table> <thead> <tr> <th>waiterid</th> <th>restid</th> <th>name</th> </tr> </thead> <tbody data-bind="foreach: waiters"> <tr> <td data-bind="text: waiter_id"></td> <td data-bind="text: rest_id"></td> <td data-bind="text: name"></td> </tr> </tbody> </table> <br /> @scripts.render("~/bundles/mybundle") <input type="button" id="btngetwaiters" value="get waiters" data-bind="click: getwaiters" /> , following in js file: var waiterviewmodel = function () { //make self 'this' reference var self = this; //declare observable bind ui self.waiter_id = ko.observable("0"); self.rest_id = ko.observable("0"); self.name = ko.observable(""); //the object stored data entered in observables var waiterdata = { waiter_id: self.waiter_id, rest_id: self.rest_id, name: self.name }; //declare observablearray storing json response self.waiters = ko.observablearray([]); getwaiters(); //call function gets records using ajax call //function read employees function getwaiters() { alert("fetching"); //ajax call employee records $.ajax({ type: "get", url: "/api/waiterapi", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) { self.waiters(data); //put response in observablearray }, error: function (error) { alert(error.status + "<--and--> " + error.statustext); } }); //ends here } }; ko.applybindings(new waiterviewmodel());
when trying bind click event binding method should method of view model in implementation getwaiters()
declared private method. define method , try again:
self.getwaiters = function() { // code };
Comments
Post a Comment