I have a bootstrap nav-tab and I want to display dynamically content when I select a tab. Ajax returns an array of Results. Each result has Price,Logo,Companyname and an array of Covers. Each cover has Price,MaxCover,Optional and Description. Rest of html code is here link but now I want to return a more complex type.
<script type='text/javascript'>
var cover = new
{
Price: ko.observable(),
MaxCover: ko.observable(),
Optional: ko.observable(),
Description: ko.observable(),
}
var result = new
{
Price: ko.observable(),
InsLogo: ko.observable(),
CompanyName: ko.observable(),
Covers: ko.observableArray()
};
var tab = function (Id, name, selected) {
this.Id = Id;
this.name = name;
this.Results = ko.observableArray();
this.isSelected = ko.computed(function () {
return this === selected();
}, this);
}
var ViewModel = function () {
var self = this;
self.selectedTab = ko.observable();
self.tabs = ko.observableArray([
new tab(0, 'Tab1', self.selectedTab),
new tab(1, 'Tab2', self.selectedTab),
new tab(2, 'Tab3', self.selectedTab)
]);
self.selectedTab(self.tabs()[0]);
self.selectedTab.subscribe(function () {
$.ajax({
url: '@Url.Action("GetSection")',
data: { Id: self.selectedTab().Id },
type: 'GET',
success: function (data) {
self.selectedTab().Results(data.Results); //Here I want to fill the results!!!!!!
}
});
});
}
ko.applyBindings(new ViewModel());
newwith object literals{}- in fact, that's an error. Using{}is enough.