data binding - Select option value - selectedchoice is not working -
i binding select html tag dynamic values using knockout js. additionally, trying set selected selection failing. please suggest going wrong.
self.level1choices.selectedchoice = ko.observable(2); - line not seem work.
the jsfiddle code @ http://jsfiddle.net/oarp7gwj/7/ dropdown not loading in jsfiddle reason. dont think have referenced knockout js correctly. in local environment, able load select box values. however, not able set selected value.
@wayne ellery, @qbm5 - please advise since know :)
you should utilize var declare model object avoid scoping issues
var viewmodel = new datamodel();
the main issue need add together datamodel exposing through variable in datamodel.
var datamodel = function (client) { var self = this; self.level1choices = ko.observablearray(); };
take @ helo world illustration how this:
http://knockoutjs.com/examples/helloworld.html
i've scoped self it's best practice not worry referring else mentioned here: http://knockoutjs.com/documentation/computedobservables.html.
i moved loadallapprovers method within datamodel belongs , has access populate datamodel. added mobile services client constructor can mocked testing model.
var datamodel = function (client) { var self = this; self.level1choices = ko.observablearray(); var loadallapprovers = function () { var allappprovers = client.gettable('table'); var query = allappprovers.select("id", "firstname").read().done(function (approverresults) { self.level1choices(approverresults); }, function (err) { console.log("error: " + err); }); }; loadallapprovers(); };
you missing knockout in jsfiddle.
http://jsfiddle.net/az4rox0q/6/
data-binding knockout.js
No comments:
Post a Comment