I have a jquery function gets a all teams from a service. How would i data-bind this to a select box?
function GetAvailableTeams() {
$.support.cors = true;
var jqxhr =
$.getJSON('http://localhost/Service.svc/GetTeamsAll',
function (data) {
teamViewModel.clearTeams();
$.each(data.GetTeamsAllResult,
function (key, val) {
teamViewModel.addTeam(val.TeamId, val.TeamName, true);
}
ko.applyBindings(teamViewModel, document.getElementById("teamNameLabel"));
})
.success(function () { })
.error(function () { alert("Encountered error with the service: GetTeams. "); })
.complete(function () { });
}
You just have to set up the correct properties of the select element and the
api will do it for you.
Ex:
knockoutjs mapping select data-bind options
http://jsfiddle.net/madcapnmckay/Ba5gx/