Note that there are some explanatory texts on larger screens.

plurals
  1. POPass a function that returns the value of the ko.computed
    primarykey
    data
    text
    <p>I have two functions <code>generate</code> and <code>test</code>. When the user clicks a button <code>generate</code> is called which then calls <code>test</code> function. I receive the following error:</p> <blockquote> <p>Pass a function that returns the value of the ko.computed.</p> </blockquote> <p>The error is thrown on this line in the test function.: </p> <pre><code>var unmapped = ko.mapping.toJS(this); </code></pre> <p><code>this</code> is my viewmodel with ko.observable properties.</p> <p>Here are the two functions. If I move the content of <code>test</code> function to <code>generate</code> everything works fine but I need the logic to be in two different functions. What can I do?</p> <p>I am very stuck here. Any help will be greatly apreciated.</p> <pre><code>generate = function () { if (!omega.validatableFranchiseGeneration.validate()) { return false; } omega.franchiseInfo.IsForGeneration(true); test(); } var test = function () { getIpsAndPorts(); for (var i = 0; i &lt; omega.franchiseInfo.LanguagesInfoViewModel().length; i++) { if ($.isArray(omega.franchiseInfo.LanguagesInfoViewModel()[i].SubMenuItemsViewModel)) { omega.franchiseInfo.LanguagesInfoViewModel()[i].SubMenuItemsViewModel = omega.franchiseInfo.LanguagesInfoViewModel()[i].SubMenuItemsViewModel[0]; } } var unmapped = ko.mapping.toJS(this); var jsonData = ko.toJSON(unmapped); $.ajax({ url: "/franchise/Save", type: "POST", // data: ko.toJSON({ folderName: FolderName }), data: { franchiseInfoViewModel: jsonData }, //traditional: true, //contentType: "application/json; charset=utf-8", dataType: 'json', success: function (data, textStatus, xhr) { window.location.href = data.redirectToUrl; }, error: function (request, status, error) { jsonValue = jQuery.parseJSON(request.responseText); omega.franchiseInfo.errorMessages([]); for (var i = 0; i &lt; jsonValue.errorMessages.length; i++) { omega.franchiseInfo.errorMessages.push({ errorMessage: ko.observable(jsonValue.errorMessages[i].ErrorMessage) }); } for (var i = 0; i &lt; omega.franchiseInfo.LanguagesInfoViewModel().length; i++) { InitializeViewLanguagesInfo(omega.franchiseInfo.LanguagesInfoViewModel()[i]); } } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload