0
votes

I'm unable to send data to a new window in extjs. Following the answer to this question, I've set a window property to the value I need in the new window:

function OpenAddSampleWindow(datasetid)
{
  var VIEW_WIDTH = $(window).width();   // returns width of browser viewport
  var VIEW_HEIGHT = $(window).height();   // returns height of browser viewport



  win = Ext.create('widget.window', {
    title: 'Add Sample',
    id: 'AddSampleWindow',
    closable: true,
    closeAction: 'destroy',
    width: VIEW_WIDTH,
    minWidth: 600,
    height: VIEW_HEIGHT,
    minHeight: 400,
    modal: true,
    layout: 'fit',
    items : [{
       xtype : "component",
       autoScroll: true,
       autoEl : {
       tag : "iframe",
       src : "sample_add.html"
    }
  }]
 });
 win.datasetid=datasetid;
win.show();
return win;
}

Then, the javascript for the new window has the following function that runs when the page loads:

Ext.onReady(function(){
    alert(window.datasetid);
});

all that shows up in the alert box is "undefined" I've also tried win.datasetid, but then I get an error that win is undefined.

What am I doing wrong? How can I access this data?

1
What is the problem exactly ? console.log() does not output anything ? From what I see, this should work OK. Put a debugger; statement above the log statement and explore the win object.Francis Ducharme
I don't want the values output to the console. I want them to be available to javascript functions for the new window. Looking in the debugger, the win object has the data I expect. I just don't know how to access it.Richard
javascriptFunction(win.myExtraParams.a, win.myExtraParams.b); ?Francis Ducharme
win isn't defined within the new window...Richard
Then post a new question or edit this one with the complete code and where you get the undefined error.Francis Ducharme

1 Answers

0
votes

window.datasetid doesn't work because you are alerting a non-standard property on the browsers window object. win.datasetid probably doesn't work because you are not invoking the OpenAddSampleWindow function. This is still bad practice though because you are using a global to get a reference to the win. I think the better solution would be to not use a global.

    function OpenAddSampleWindow(datasetid)
{
  var VIEW_WIDTH = $(window).width();   // returns width of browser viewport
  var VIEW_HEIGHT = $(window).height();   // returns height of browser viewport

  var win = Ext.create('widget.window', {
  //...
return win;
}

And invoke the function and then call the local variable whatever you want.

Ext.onReady(function(){
    var winA2 = OpenAddSampleWindow('a1');
    alert(winA2.datasetid);
})