我想跨应用程序获取所有 Ext.MessageBox.alert() 并将其设置到新位置。 我们的应用程序中有许多 jsp 页面,我们在其中使用了 Ext.MessageBox.alert(),现在的要求是重新定位所有消息框,而不触及它们在 jsp 中的代码..我可以包含一个 js 文件
选项 1: 我发现我可以通过以下方式重新定位消息警报:https://stackoverflow.com/questions/1...l-align-with-y 但是我必须更改所有 jsp 页面并添加:
msgBox=Ext.MessageBox.alert(jsonData.responseMessage);
msgBox.getPositionEl().setTop(50);
选项2:扩展消息框:仍然更改所有jsp
选项 3:使用 css:不知道怎么做?
如果有任何其他解决方案或者 Css 解决方案就可以了,谁能指导我:
我的代码如下
Ext.Ajax.request({
url : 'submitAddZone.htm',
params : {
zoneName : Ext.getCmp('zoneNameId').getValue(),
emailParam : Ext.getCmp('emailId').getValue(),
requestTypeParam : Ext.getCmp('requestTypeId').getValue(),
level : selectedLevel + 1,
parentZoneName : selectedParentZone,
currency : currencyValue,
startDate : Ext.getCmp('startDateId').getValue(),
startTime : Ext.getCmp('startTimeId').getValue()
},
method : 'POST',
success : function(response,request) {
toggleAddZoneElements();
var jsonData = Ext.decode(response.responseText);
if(jsonData.isSuccess){
msgBox= Ext.MessageBox.alert(jsonData.responseMessage);
msgBox.getPositionEl().setTop(50);
addZoneWin.close();
toggleAddZoneButtons();
tree.getStore().load({url: 'loadCustomerStructure.htm'});
}else{
Ext.getCmp('sendRequest').setIcon();
Ext.getCmp('errorMessage1').setText(Encoder.htmlDecode(jsonData.errorMessage));
Ext.getCmp('errorMessage1').show();
}
},
failure : function(
response) {
toggleAddZoneElements();
msgBox= Ext.MessageBox.alert(notCreatedLabel);
addZoneWin.close();
msgBox.getPositionEl().setTop(50);
}
});
最佳答案
一个干净的解决方案是创建您自己的 MessageBox 类,它提供自定义警报方法,您可以在其中调用 Ext.MessageBox.alert() 并更改位置。但这需要您更改所有 jsp 文件。
现在它变脏了:您可以尝试覆盖 Ext.MessageBox.alert:
Ext.override(Ext.MessageBox,{
alert: function(message){
var msgBox = Ext.MessageBox.alert(message);
msgBox.getPositionEl().setTop(50);
}
});
但这会影响对 Ext.MessageBox.alert() 的所有调用。我不想在我的代码中有这样的 hack。
关于javascript - 在不更改当前代码的情况下重新定位 Ext.MessageBox.alert(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17723540/