[英]how to set window's title according to a file i choose in extjs
I have a scroll menu contain files names. 我有一个包含文件名的滚动菜单。 When I click on a file name in the menu, I want to create a window has the file name as a title. 当我单击菜单中的文件名时,我想创建一个窗口,将文件名作为标题。
In the code below I can create the window but without a title. 在下面的代码中,我可以创建窗口,但没有标题。
The problem is in the line ( title: jsonobj[ii], // I got undefined here ). 问题在于行(标题:jsonobj [ii],//我在这里未定义)。
var scrollMenu = Ext.create('Ext.menu.Menu');
var files = Ext.Ajax.request({
url: 'php/getfiles.php',
success: function(response, opts) {
var jsonobj = Ext.decode(response.responseText);
for(var ii = 0; ii < jsonobj.length; ii++){
scrollMenu.add({
text: jsonobj[ii], // working good
handler: function () {
var winfile = Ext.create('widget.window', {
region: 'center',
height: 500,
width: 900,
x: 500,
y: 100,
title: jsonobj[ii], // not working
closable: true,
plain: true,
layout: 'fit',
preventBodyReset: true,
});
winfile.show();
}
});
}
},
failure: function(response, opts) {
console.log('somthing went wrong with this AJAX call' + response.status);
}
});
The problem is that all handler
callbacks are defined in the same closure. 问题是所有handler
回调都在同一个闭包中定义。 That means that once ii
is changed in scope of success
callback - it automatically affects all handler
callbacks. 这意味着一旦ii
success
回调范围发生变化 - 它会自动影响所有handler
回调。 Since jsonobj[jsonobj.length] === undefined
you always get undefined title. 由于jsonobj[jsonobj.length] === undefined
你总是得到未定义的标题。 You should wrap handler
with some other closure like below: 您应该使用如下的其他闭包来包装handler
:
handler: (function(){
var title = jsonobj[ii];
return function () {
var winfile = Ext.create('widget.window', {
region: 'center',
height: 500,
width: 900,
x: 500,
y: 100,
title: title,
closable: true,
plain: true,
layout: 'fit',
preventBodyReset: true
});
winfile.show();
}
}())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.