如何在 EXTJS 中添加 window 定向监听器?
How to add window orientation listeners in EXTJS?
如何定义仅附加到特定视图的 window 定向侦听器?
例如,如果移动设备是纵向的,我想显示两列网格,否则我会显示更多列。
在搜索解决方案后,我找到了思路here and here
但是,我不知道如何为该事件添加侦听器,特别是该侦听器应该只对特定视图有效,而不是对整个应用程序有效。
您可以在视图的 'initialize' 中使用 Viewport 的 'orientationchange' 事件处理程序,如下所示:
Ext.create('Ext.Panel', {
title: 'My Panel',
fullscreen: true,
items: [{
xtype: 'textfield',
label: "Orientation",
listeners: {
initialize: function (field) {
Ext.Viewport.on('orientationchange', function (viewPort, newOrientation, width, height) {
field.setValue(newOrientation);
});
}
}
}]
});
如何定义仅附加到特定视图的 window 定向侦听器? 例如,如果移动设备是纵向的,我想显示两列网格,否则我会显示更多列。
在搜索解决方案后,我找到了思路here and here
但是,我不知道如何为该事件添加侦听器,特别是该侦听器应该只对特定视图有效,而不是对整个应用程序有效。
您可以在视图的 'initialize' 中使用 Viewport 的 'orientationchange' 事件处理程序,如下所示:
Ext.create('Ext.Panel', {
title: 'My Panel',
fullscreen: true,
items: [{
xtype: 'textfield',
label: "Orientation",
listeners: {
initialize: function (field) {
Ext.Viewport.on('orientationchange', function (viewPort, newOrientation, width, height) {
field.setValue(newOrientation);
});
}
}
}]
});