Unable to pass observable data when closing the pop-up

     return{     // The following code can be found in index.js
        addItem: function () {
        alert("working");
        Newram.show().then(function (response) `***// Calling show functionin Newram.js***`
        {
            var c = response;
        }
            );
    }}
     // In Newram.js while closing the popup I attempted to send data to the **response** in index.js but an empty string or undefined is being displayed

var AddItem = function () {
    var self = this;

        self.Name = ko.observable('jo'),
        self.Price = ko.observable(100),
        self.Sales = ko.observable("good")
        self.data1= {name:self.Name() };

};



AddItem.prototype.closeDialog = function () {
    dialog.close(this, self.Name);
};

I am unable to pass an observable data when closing a popup, even when I tried this code (dialog.close(this,ko.toJS(self.Name))).....I cannot retrieve the data in response, but if I pass a string it is available in the response

Answer №1

In order to retrieve a string from the modal dialog, you should include the following code in your dialog.close function...

var result = JSON.stringify({ Element: self.Element() });
dialog.close(this, result);

Afterwards, you can retrieve the value in your main JavaScript file like so...

YourModal.show().then(function (result) {
   var parsedResult = JSON.parse(result);
   var elementValue = parsedResult.Element;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Protractor - Resolving as pending promise when executed

I have been working on creating a function that can search through an array of elements and return the first element that meets certain criteria. Here is my test code that works as expected: element.all(by.css('_cssSelector_')).filter(function( ...

Warning: The current version of graceful-fs (3) is deprecated in npm

I encountered an issue while running npm install. I attempted to run the following command before updating: $npm install npm, and also updated graceful-fs. $ npm install -g graceful-fs <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfe ...

Creating a custom listview in Android to display JSON data

I encountered an issue while attempting to populate a custom listview with JSON data. Upon running the app, only a blank layout file is displayed. The JSON source can be found at Below is the code snippet of what I have implemented: This is the main act ...

The hover effect generates a flickering sensation

I am having trouble displaying options on an image when hovering over it, as the displayed options keep flickering. $('a').hover(function(event) { var href = $(this).attr('href'); var top = $(this).next().css("bot ...

The code provided creates a web form using HTML and ExpressJS to store submitted information into a MongoDB database. However, there seems to be an issue with the 'post' method, while the 'get' method functions correctly

When I try to submit entries (name, email, address) on localhost:3000 in the browser, the 'post' function is not creating an object in the mongo database even though it works from the postman. The browser displays an error message saying "unable ...

Ways to prevent horizontal scrolling in an image

Currently, I am working on a scrolling animation page that is optimized for mobile devices. One issue I am encountering is when an element is larger than the screen size, such as when an image is wider than the mobile device. In this scenario, the user can ...

Modify the fixed div's class when the user scrolls past a certain section

My page includes a fixed menu with various sections, each assigned a specific class name using data attributes (e.g. data-menu="black"). I want the fixed menu to change its class based on the section that is currently underneath it as the user scrolls. Y ...

Retrieving JSON data through the use of retrofit and rxjava

I'm trying to retrieve JSON data from a specific URL using Retrofit and RxJava. You can find the sample JSON data at this link: . Here's a snippet of the JSON: { "data": [ { "itemId": "1", "desc": "Batcave", "audio": "https://storage.googl ...

using the useEffect hook to create a loop that runs infinitely

For my project, I am working on updating data in firebase. The issue that I'm facing is that the data seems to be constantly looping, causing potential crashes. Is there a way to stop this loop and prevent any crashing? import "./App.css"; ...

A guide on retrieving the upload status of a file using an AJAX post request

Is there a way to retrieve the status of uploaded files when the user cancels the process while uploading multiple files using an ajax call? This is how I am currently making the ajax request to upload files: var request = $.ajax({ url: 'file ...

What could be causing my AJAX request for JSON data to fail?

I am currently working on a mobile app using PhoneGap and jQuery Mobile. I am attempting to retrieve data from a server with the following request, but it does not seem to be functioning as expected: $.ajax({ url : "https://localhost:8000/weatherD ...

Should I use Object.assign or define class properties?

Currently in the process of developing an angular application that interacts with the twitch API. The API returns data in various formats, some of which I need to parse and save into specific classes. My main concern is understanding the potential drawbac ...

Update the router URL without switching pages, yet still record it in the browser history

One of the features on my search page allows users to perform searches and view results. Initially, I faced a challenge in updating the router URL without navigating, but I managed to overcome this by utilizing the "Location" feature. In my ngOnInit meth ...

execute javascript code found in the html document

Currently, I have a bash script that utilizes curl to download a page. Then, it uses grep and sed to extract javascript within the html block to a file. Following this, I use node to evaluate and leverage the downloaded javascript. Here is an example: cur ...

What is the correct way to extract results from an Array of Objects in Typescript after parsing a JSON string into a JSON object? I need help troubleshooting my code

Here is my code for extracting data from an array of objects after converting it from a JSON string to a JSON object. export class FourColumnResults { constructor(private column1: string, private column2: string, private column3: string, priv ...

Error occurs in ASP.NET AJAX Control Toolkit while uploading files within Scriptresource.axd

I recently encountered an issue with my AJAX Control Toolkit File Upload (Version 15.1.4) in my ASP.Net Web Application. Up until this week, it was functioning perfectly fine. However, starting yesterday, I started receiving a JavaScript error right after ...

Retrieving text that has been HTML-escaped from a textarea using jQuery

Within my HTML file, I have a <textarea id="mytextarea"></textarea>. Suppose a user inputs the following text: <hello>, world! How can I retrieve res = "&lt;hello&gt;, world!"; based on the user's input? The current code s ...

GraphQL failing to communicate with WP API

Any help is appreciated! I am currently retrieving data from a WP Rest API. When I run the WordPress site locally on my machine using http://localhost:8000 and access the graphql playground at http://localhost:3000/api/graphql, everything works fine as ex ...

Issue with jQuery DataTable: Unable to use column-level filters at the top and maintain a fixed height simultaneously

I am having an issue displaying data in a jQuery DataTable with a column level filter at the top, fixed height, and scroller enabled. Initially, I was able to display the column level filter at the top and it was functioning properly. However, when I set t ...

Converting an array containing a single value into an object using JSON encoding

I am currently developing a PHP script that is responsible for handling JSON input received via a $_POST variable. The goal is to extract the data from the JSON and then upload it to an SQL database in a specific format. $object = json_decode('{ ...