无法在关闭弹出窗口时传递可观察的数据

cant able to pass a observable data while closing pop up

本文关键字:观察 数据 窗口      更新时间:2023-09-26
     return{     // this code is 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 tried to send data to the **response** in index.js but empty string or undefined  is showing
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);
};

即使我尝试了此代码( dialog.close(this,ko.toJS(self.名称(((.....无法在响应中获取数据,但是如果我传递一个字符串,它在响应中可用

您必须从模态对话框传回一个字符串。所以在你的对话框中,关闭试试这个...

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

然后,您可以访问索引中的值.js如下所示...

Newram.show().then(function (response) {
   var parsed = JSON.parse(response)
   var c = parsed.Name;
}