我正在嘗試使用新的ExtJs 5. 我已經根據定義的ExtJs5的MVC模式創建了一個小應用程序。ExtJs5:從控制器1調用控制器2的方法
上午使用ViewControllers
每個View
。
問題陳述:現在假設我有兩個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時,這不起作用。
任何人都可以指導我如何實現這件事?而且,無論是做這種事情的正確/理想的方式,還是有更好的選擇?
這裏是我的代碼:
StatusBarView:
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');
}
});
現在,我通過一個全球性的控制器來管理它。 'MyApp.app.getController('StatusBarController')。updateStatusBar()' – DarkKnightFan