【发布时间】:2014-08-05 22:15:02
【问题描述】:
我正在尝试新的 ExtJs 5。 我根据 ExtJs5 定义的 MVC 模式创建了一个小应用程序。
我为每个View 使用ViewControllers。
问题陈述:现在假设我有两个 VC(Controller1 和 Controller2)。每个都有自己的方法。我希望从 Controller1 调用 Controller2 的方法。我想从 Controller1 更新与 Controller2 关联的视图。
E.g. Suppose there is a separate view for Status Bar and a ViewController(StatusBarController).
This VC has a method to update the view based on whatever message it receives as input parameter.
All the other controllers in the application will call this VCs method to update the status of the application on the status bar.
在以前的版本中,this.getController('StatusBarController') 用于获取任何控制器的句柄,然后调用其方法。
但是当我使用 ViewController 时,这在我的情况下不起作用。
谁能指导我如何实现这个目标?还有这是否是做这件事的正确/理想方式还是有更好的选择?
这是我的代码:
状态栏视图:
Ext.define('MyApp.view.statusbar.StatusBarView', {
extend : 'Ext.panel.Panel',
controller: 'StatusBarController',
region : 'south',
xtype : 'status-bar-panel',
html : 'This is a status bar'
});
StatusBarController:
Ext.define('MyApp.controller.StatusBarController', {
extend : 'Ext.app.ViewController',
alias: 'controller.StatusBarController',
updateStatusBar : function(message) {
this.getStatusBarView().update(message);
}
});
应用中的其他一些控制器:
Ext.define('MyApp.controller.ResourcesPanelController', {
extend : 'Ext.app.ViewController',
alias : 'controller.ResourcesController',
onItemClick : function(tree, record, item, index, e, eOpts) {
// here I am calling the other controller's method.
this.getController('StatusBarController').updateStatusBar(
record.data.text + ' has been clicked');
}
});
【问题讨论】:
标签: javascript extjs model-view-controller extjs5