2015-04-07 46 views
0
 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(通過一個可觀察到的數據這一點,ko.toJS(self.Name)) ).....不能夠獲得響應的數據,但如果我傳遞一個字符串它可在響應斜面能夠同時關閉彈出

+0

'self'不'closeDialog'定義方法,嘗試用'this'代替它 –

+0

如果我使用「this」..... self.Name沒有定義 – Joel

回答

0

您必須從模式對話框傳回一個字符串。因此,在您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; 
}