【问题标题】:cant able to pass a observable data while closing pop up关闭弹出窗口时无法传递可观察数据
【发布时间】:2015-04-07 07:13:13
【问题描述】:
     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.Name))),我也无法在关闭弹出窗口时传递可观察的数据......无法在response 但如果我传递一个字符串,它可以在响应中使用

【问题讨论】:

  • self 没有在closeDialog 方法中定义,尝试用this替换它
  • 如果我使用 "this" .....self.Name 未定义

标签: javascript json knockout-2.0 durandal-2.0


【解决方案1】:

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

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

然后您可以像这样访问 index.js 中的值...

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 2015-10-09
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多