加载页面时在 Extjs 中显示消息框
Displaying message box in Extjs when the page is loaded
我正在学习 extjs,因为我们的应用程序使用它。现在我已经能够构建类似的东西:
blur: function(field, lastValues) {
var vField = field.getValue(),
vFormPanel = field.formPanel;
if (Ext.isEmpty(vField)) {
MsgBox.show({
msgs: [{
type: 'info',
msg: Lang.getCustomFrameworkMessage('Do you want to search google?')
}],
buttons: MsgBox.YESNO,
fn: function(buttonId) {
if (buttonId === "yes") {
var redirect = 'https://google.com'
window.location.href = redirect;
}
}
}
}
}
}
在上面的代码中,当字段被tab 入和出并且为空时,它显示消息框。相反,我希望在加载页面时,立即显示消息框。怎么办??
您已经使用 blur
事件来完成您的任务。您可以使用 afterrender 事件来显示您的消息。
这将取决于您的 app/UI 中有什么,但一般的想法是查看您想要绑定的事件的文档,然后在其中添加您的处理程序。
这是一个示例应用程序:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
html: '<p>World!</p>',
renderTo: Ext.getBody(),
listeners: {
afterrender: function() {
Ext.Msg.alert('TEST')
}
}
});
}
});
Here is a demo in Sencha Fiddle
注意:演示和示例在 Sencha ExtJS 5.1
我正在学习 extjs,因为我们的应用程序使用它。现在我已经能够构建类似的东西:
blur: function(field, lastValues) {
var vField = field.getValue(),
vFormPanel = field.formPanel;
if (Ext.isEmpty(vField)) {
MsgBox.show({
msgs: [{
type: 'info',
msg: Lang.getCustomFrameworkMessage('Do you want to search google?')
}],
buttons: MsgBox.YESNO,
fn: function(buttonId) {
if (buttonId === "yes") {
var redirect = 'https://google.com'
window.location.href = redirect;
}
}
}
}
}
}
在上面的代码中,当字段被tab 入和出并且为空时,它显示消息框。相反,我希望在加载页面时,立即显示消息框。怎么办??
您已经使用 blur
事件来完成您的任务。您可以使用 afterrender 事件来显示您的消息。
这将取决于您的 app/UI 中有什么,但一般的想法是查看您想要绑定的事件的文档,然后在其中添加您的处理程序。
这是一个示例应用程序:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
html: '<p>World!</p>',
renderTo: Ext.getBody(),
listeners: {
afterrender: function() {
Ext.Msg.alert('TEST')
}
}
});
}
});
Here is a demo in Sencha Fiddle
注意:演示和示例在 Sencha ExtJS 5.1