viewModel = {
init: function () {
$.ajax({
type: 'GET',
url: 'adminprodotto/init',
async: false,
contentType: 'application/json; charset=utf-8',
success: function (data) {
$.extend(viewModel, ko.mapping.fromJS(data));
/*ko.utils.unwrapObservable(viewModel.Immagini);*/
},
error: function () {
}
});
},
vuoto: function () {
$.ajax({
type: 'GET',
url: 'adminprodotto/init',
async: false,
contentType: 'application/json; charset=utf-8',
success: function (data) {
ko.mapping.fromJS(data, viewModel)
},
error: function () {
}
});
},
save: function () {
//alert(ko.mapping.toJSON(viewModel.Allegati));
$.ajax({
type: 'POST',
url: 'adminprodotto/update',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(ko.mapping.toJS(viewModel)),
success: function (data) {
$('#modal-prodotto').modal('hide');
tabellaProdotti.fnStandingRedraw();
},
error: function (jqXHR, textStatus, errorThrown) { alert('Errore:' + errorThrown) }
});
},
edit: function (key) {
$.ajax({
type: 'GET',
async: false,
url: 'adminprodotto/detail?IdProdotto=' + key,
contentType: 'application/json; charset=utf-8',
success: function (data) {
ko.mapping.fromJS(data, viewModel);
$('#modal-prodotto').modal('show');
},
error: function (jqXHR, textStatus, errorThrown) { alert('Errore:' + errorThrown) }
});
},
erase: function () {
$.ajax({
type: 'POST',
url: 'adminprodotto/delete',
async: false,
data: JSON.stringify({ IdProdotto: viewModel.Prodotto.IdProdotto() }),
contentType: 'application/json; charset=utf-8',
success: function (data) {
$("#modal-delete-prodotto").modal('hide');
tabellaProdotti.fnStandingRedraw();
},
error: function (jqXHR, textStatus, errorThrown) { alert('Errore:' + errorThrown) }
});
},
annulla: function () {
tabellaProdotti.fnStandingRedraw();
},
removeImmagine: function (immagine, data) {
immagine = ko.mapping.toJS(immagine);
$.ajax({
type: 'POST',
url: '/file/deletefileimmagine',
async: false,
data: JSON.stringify({ Url: immagine.Url, IdProdottoImmagine: immagine.IdProdottoImmagine }),
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data == "ok") {
viewModel.Immagini.remove(function (item) {
return (item.IdProdottoImmagine() == allegato.IdProdottoImmaginr)
});
}
},
error: function (jqXHR, textStatus, errorThrown) { alert('Errore:' + errorThrown) }
});
return true;
},
removeAllegato: function (allegato, data) {
allegato = ko.mapping.toJS(allegato);
$.ajax({
type: 'POST',
url: '/file/deletefileallegato',
async: false,
data: JSON.stringify({ Url: allegato.Url, IdProdottoAllegato: allegato.IdProdottoAllegato }),
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data == "ok") {
viewModel.Allegati.remove(function (item) {
return (item.IdProdottoAllegato() == allegato.IdProdottoAllegato)
});
}
},
error: function (jqXHR, textStatus, errorThrown) { alert('Errore:' + errorThrown) }
});
return true;
}
}
after five o six call to the "save" method of the viewmodel the call toJSON (i've tried with toJS same issue) cause a memory leak. I've tried the latest version of the plugin (debug version) and knockout (in chrome says thant the page is crashed, in firefox that a script doesn't respond anymore).