Got an old project in .net that needs few new features. We have a major problem with knockout somehow when pressing button for the first time everything works as it should, but when it is pressed for the second time it goes kaput. Error
GeneratedCode.ts:5564 Uncaught TypeError: source.accountNumber is not a function
at _Mapper.unwrapPnsBankReportListItem (GeneratedCode.ts:5564)
at Function._Mapper.convert (GeneratedCode.ts:4673)
at Function._Mapper.unwrapDlgBankReportViewModel (GeneratedCode.ts:4714)
at DlgBankReport.OnClickSearchButton (DlgBankReport.ts:102)
at Object.eval (eval at createBindingsStringEvaluator (knockout-3.1.0.debug.js:2437), <anonymous>:3:101)
at HTMLButtonElement.<anonymous> (knockout-3.1.0.debug.js:3108)
at HTMLButtonElement.dispatch (jquery-2.1.0.js:4371)
at HTMLButtonElement.elemData.handle (jquery-2.1.0.js:4057)
cshtml button
<div class="col-md-3">
<button type="button" class="btn btn-block click-by-enter btn-primary"
data-bind="click: function (data, event) { $root._Dialog.OnClickSearchButton($root, function (r) { $root._mapViewModel(r); }); }">Meklēt</button>
</div>
ts
public OnClickSearchButton(modelObservable: Pns.Models.ViewModels.DlgBankReportViewModelObservable, success: (r: Pns.Models.ViewModels.DlgBankReportViewModel) => any): void {
var focusElem = $(':focus');
Pns.Instance.showPleaseWaitDlg();
const obs = Pns.Models.ViewModels._Mapper.unwrapDlgBankReportViewModel(modelObservable);
DynamicLocator.CreateProxy("Pns.Business.Dialogs.DlgBankReport", null, (<any>window).PnsInstance._connection, function (dlg: Pns.Business.Dialogs.DlgBankReport) {
$.ajax(Pns.Configuration.ApiRootUri + "AccountReport/rpc/ExecuteCreation", {
data: JSON.stringify(obs),
dataType: 'json',
contentType: 'application/json',
type: 'POST',
success: function (modelResult: Pns.Models.ViewModels.DlgBankReportViewModel) {
},
error: function () {
}
});
});
}
it breaks down at this line in ts with said error.
const obs = Pns.Models.ViewModels._Mapper.unwrapDlgBankReportViewModel(modelObservable);
Have no clue why it doesnt work, as everywhere else it works as it should work. If anyone has idea why and how to fix it please let me know. Models are generated so there are no mistakes in them. Error happens inside list with other model. Its mapping is also code generated and works elsewhere, this is the only place where it breaks down.