Populating dropdown using Jock Knockout parameter using json object returned by ajax call
I am using knockout js for data binding in my single page web application, I need to populate a dropdown using the json object returned as a response in an ajax call to the server. I am adding my model and ajax call here. Please suggest solutions.
var permissionRequestModel = {
fromDate: ko.observable(''),
toDate: ko.observable(''),
fulldayPermission: ko.observable(false),
fromTimeHH: ko.observable(''),
fromTimeMM: ko.observable(''),
toTimeHH: ko.observable(''),
toTimeMM: ko.observable(''),
permissionTypeOne: ko.observable(''),
permissionTypeTwo: ko.observable(''),
approverList: ko.observableArray([]),
reasonLeave: ko.observable('')
};
//ajax call
$(function () {
$.ajax({
url: "http://ec2-107-20-7-114.compute-1.amazonaws.com/adco/api/Request/permission?appid=1&opertype=requestor&employeeNo=1000416",
type: "GET",
contentType: "application/json",
dataType: "json",
error: function () {
alert("failed");
},
success: function (data) {
alert("Success");
}
});
});
I need to populate the ApproverList (ko.observablearray) with a json response.
+3
source to share
1 answer
Usage of the Knockout Display Plugin :
approverList = ko.mapping.fromJS(data);
Or if you want to update an already populated view model:
success: function (data)
{
ko.mapping.fromJS(data, approverList);
}
+3
source to share