leveille
4 Aug 2007, 5:30 PM
In the app I am working on, when I lazy initialize my dialog it cause one of my variables to behave very strangely. The variable is blockId. This section of code is part of a function that is called as part of a click event for a group of elements on my page. The id of the element which has been clicked is stored in blockId. The first element I click sends its id to this function, and the function executes properly. With ever successive click, the correct id is sent down to blockId, however somehow the very same variable blockId within the lazy initialized block is retaining it's value from the previous element click.
I'm sure this has to do with my lack of understanding of lazy initializing, however how can I "reset" the value of a referenced variable in this block with each click event?
function showDialog(id, data){
var blockId = id;
var animate = Ext.get(blockId);
alert(blockId);
if(!dialog)
{
dialog = new Ext.LayoutDialog("bai-dialog", {
modal:true,
resizable:false,
width:594,
height:383,
shadow:true,
proxyDrag: true,
closable: false,
center: {
autoScroll:true
}
});
dialog.addKeyListener(27, function(){
cancel(dialog, blockId);
}, dialog);
dialog.setDefaultButton(dialog.addButton('Cancel', function(){
cancel(dialog, blockId);
}, dialog));
dialog.addButton('Submit', function(){
var editorData = HtmlEditor.getValue();
alert(blockId);
save(editorData, dialog, blockId);
}, dialog);
var layout = dialog.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('bai-center'));
layout.endUpdate();
}
alert(blockId);
HtmlEditor = new Ext.form.HtmlEditor({
//enableColors: false,
enableFont: false,
enableFontSize: false,
name: 'bai-body',
value: data
});
HtmlEditor.setSize(570, 310);
jQuery("#bai-center").empty();
HtmlEditor.render('bai-center');
dialog.show(animate.dom);
}
I'm sure this has to do with my lack of understanding of lazy initializing, however how can I "reset" the value of a referenced variable in this block with each click event?
function showDialog(id, data){
var blockId = id;
var animate = Ext.get(blockId);
alert(blockId);
if(!dialog)
{
dialog = new Ext.LayoutDialog("bai-dialog", {
modal:true,
resizable:false,
width:594,
height:383,
shadow:true,
proxyDrag: true,
closable: false,
center: {
autoScroll:true
}
});
dialog.addKeyListener(27, function(){
cancel(dialog, blockId);
}, dialog);
dialog.setDefaultButton(dialog.addButton('Cancel', function(){
cancel(dialog, blockId);
}, dialog));
dialog.addButton('Submit', function(){
var editorData = HtmlEditor.getValue();
alert(blockId);
save(editorData, dialog, blockId);
}, dialog);
var layout = dialog.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('bai-center'));
layout.endUpdate();
}
alert(blockId);
HtmlEditor = new Ext.form.HtmlEditor({
//enableColors: false,
enableFont: false,
enableFontSize: false,
name: 'bai-body',
value: data
});
HtmlEditor.setSize(570, 310);
jQuery("#bai-center").empty();
HtmlEditor.render('bai-center');
dialog.show(animate.dom);
}