knockout.js - How to access knockout viewmodel from javascript -
i trying understand how manage scope in javascript code. once create viewmodel, how access rest of javascript? (last line in code generates 'not defined' error
note: have found several posts on differences between function/var ko, none have said there scoping advantage using var... have tried both methods.
//function appviewmodel() { // this.gridsize = ko.observable("30"); // this.canvaswidth = ko.observable("600"); // this.canvasheight = ko.observable("600"); // this.displaycoords = "axial"; // this.pixel="0"; // this.hex="0"; //} //ko.applybindings(new appviewmodel()); var appviewmodel = { gridsize: ko.observable("30"), canvaswidth: ko.observable("600"), canvasheight: ko.observable("600"), displaycoords: "axial", pixel:"0", hex:"0" }; ko.applybindings(appviewmodel ); var test = appviewmodel.gridsize;
ko.observable function , reference observable value have have brakets
e.g. example above
var test = appviewmodel.gridsize();
found explanation http://knockoutjs.com/documentation/observables.html
Comments
Post a Comment