How to wait for data to load and then print html content?
Here is HTML markup:
<div id="item-details-content">
<input type="hidden" id="item-id" value="@id" data-bind=""/>
<div class="item-list" data-bind="init: itemPage.loadcontent(@id), with: itemPage.item">
<div class="item-container clearfix">
<div class="item-content clearfix">
<div class="title" data-bind="text: Title">
Here is JS markup:
var itemViewModel = {
item: {},
loadcontent: function (getID) {
$.ajax({
url: '/api/item/details/' + getID,
dataType: 'json',
success: function (data) {
itemViewModel.item = data;
}
});
}
};
var mainViewModel = {
indexPage: indexViewModel,
itemPage: itemViewModel
};
Observations
- When the variable is
ko.observable()it eventually shows the data, problem is I don’t want it to update.
Something like this should work.
another approach would be to use a hidden class on your #item-details-content div and just do $(‘#item-details-content’).show();