Window object in success()
and in someFunction()
are not same as Ext.widget
will create a separate instance in both the functions. so data wont be persisted. To persist the data you can either use a config
or viewModel
.
I have created a sample code as per your scenarios to persist the data on window close using configs which acts kind of global to that specific view and its controller.
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create("Ext.form.Panel",{
renderTo: Ext.getBody(),
config: {
win: Ext.widget('window'), //if we store window, on close we loose it
data: "" //it will persist, so this can be used
},
items: [
{
xtype: 'button',
text: 'call',
handler: function(){
var me = this;
Ext.Ajax.request({
url: 'data1.json',
success: function(response, opts) {
var data = Ext.decode(response.responseText);
var window = me.up().config.win;
me.up().config.data = data;
window.data = data;
window.show();
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});
}
}, {
xtype: 'button',
text: 'Get Value',
handler: function(){
console.log(this.up().config.win.data);
console.log(this.up().config.data);
}
}
]
});
}
});
Here the handler for first button will represent your ajax calls success
and handler for second button represents your someFunction
.
Here i kept two configs, win and data. win is a window object which will be destroyed on close so we cant use it. second is data which is a normal variable, which will be persisted unless respective view will be destroyed. so you can use 2nd config.
You can find working fiddle here.