I am working on Single page Application (durundaljs and knockjs for UI). on the view.js file
var vm= = function() {
Id: ko.observable();
Name: ko.observable();
description: ko.observable();
parentName:ko.observable();
}
on the page activate()
method I am assigning values to observable properties.
var activate = function(Id) {
getUserGroup(Id);
};
var getUserGroup = function(Id) {
var ajaxOptions = {
url: 'Api/Group/Get?id=' + Id,
type: 'GET',
dataType: 'json'
};
function gotUserGroup(data) {
vm.Id = data.Id;
vm.Name = data.name;
vm.description = data.description;
vm.parentName =getName(data.parentId)
}
return $.ajax(ajaxOptions).then(gotUserGroup);
};
function getName(Id)
{
var ajaxOptions = {
url: 'Api/Client/Get?Id=' + Id,
type: 'GET',
dataType: 'json'
};
function getValue(data) {
return data.name;
}
$.ajax(ajaxOptions).then(getValue);
}
the issue I am facing is I am not able to get value assigned to the parentName
property.
I have a query like how can we bind in knockoutjs.
Here in my situation,i need to get parentId
value and based on it get the parentname
.
and that value should bind to the parentName
property.
Can anyone suggest how can i achieve this.