从FormController中访问功能,即可快速创建 [英] Accessing functions in ViewController from form created on-the-fly

查看:116
本文介绍了从FormController中访问功能,即可快速创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

视图控制器将处于活动状态,但它将控制许多其他视图的一个子视图,因此我认为还有其他主动视图控制器。

The view controller will be active, but it will be controlling one sub-view of many other views, so I think there will be other active view controllers.

基本上,该表单由完全不同的调度程序创建,组件和处理程序等,视图控制器和表单之间没有直接的连接。

By on-the-fly basically the form is created by a completely different dispatcher, with components and handlers, etc. with no direct connection between the view controller and the form.

视图控制器有几个功能,我需要从以下内容获取结果:

The view controller has several functions I need to get results from:

canContinue: function (arg1) {var result = true; /*...*/ return result;}
getStatus: function (arg1, arg2) {var result = 0; /* ... */ return result;}

/ * .. 。* / 表示代码省略。所以我想访问视图控制器和这些功能。以下这些线条:

/*...*/ means code omitted. So I want access to the view controller and these functions. Something along these lines:

var controller = /* how to get it? */;

if (!controller.canContinue(p))
    alert(controller.status(q, r));

我看到不建议以这种方式直接访问函数,所以尝试触发事件,但我似乎没有得到结果,我需要。

I read it is not recommended to access functions directly in this manner, so tried firing events, but I can't seem to get results back, which I need.

我以为我可以给视图控制器一个 itemId ,然后执行 Ext.ComponentQuery.query('#itemId'),但它似乎不起作用。我想一个视图控制器不是一个组件,是有道理的。

I thought I could give the view controller an itemId, and do Ext.ComponentQuery.query('#itemId'), but it doesn't seem to work. I guess a view controller isn't a component, makes sense.

视图控制器有一个唯一的类和别名,只有一个这些视图控制器有效一时间,如果这有帮助。

The view controller has a unique class and alias, and there will be only one of these view controllers active at a time, if that helps.

我可能错过了一些非常简单的事情。欢迎任何帮助。

I'm probably missing something really easy. Any assistance would be welcome.

推荐答案

我不太确定你的问题。这是我的理解:你有不同的看法,他们之间没有直接的关系。但是你想要达到对方视图的控制器。如果是,请检查这个小提琴: https://fiddle.sencha.com/#fiddle/urg

I am not quite sure about your question. Here is what I understand: You have different views and there is no direct relation between them. But you want to reach each other view's controller. If so, please check this fiddle: https://fiddle.sencha.com/#fiddle/urg

否则,我宁愿准备一个小提琴,显示你的问题。

Otherwise, I'd prefer you prepare a fiddle, which show your problem.

Ext.define('FirstPanel', {
            extend: 'Ext.panel.Panel',
            controller: 'FirstPanelController',
            layout: 'fit',
            itemId: 'firstPanel',
            items: [{
                xtype: 'button',
                text: 'FirstPanel Button',
                handler: 'FirstButtonClick'
            }]
        });
        Ext.define('FirstPanelController', {
            extend: 'Ext.app.ViewController',
            alias: 'controller.FirstPanelController',
            FirstButtonClick: function(button) {
                var me = this;
                var SecondPanelController = me.getView().mainView.down('#secondPanel').getController();
                SecondPanelController.FirstButtonClick();
                console.log('FirstButton Click');

            },
            SecondButtonClick: function() {
              alert('You are in FirstPanelController');  
            },
            init: function() {
                var me = this;     
            }
        });

        Ext.define('SecondPanelController', {
            extend: 'Ext.app.ViewController',
            alias: 'controller.SecondPanelController',
            SecondButtonClick: function(button) {
                var me = this;
                var FirstPanelController = me.getView().up().down('#firstPanel').getController();
                FirstPanelController.SecondButtonClick();
                console.log('SecondPanelController');

            },
            FirstButtonClick: function() {
                alert('You are in SecondPanelController');
            },
            init: function() {
                var me = this;     
            }
        });

        Ext.define('SecondPanel', {
            extend: 'Ext.panel.Panel',
            controller: 'SecondPanelController',
            layout: 'fit',
            itemId: 'secondPanel',
            items: [{
                xtype: 'button',
                text: 'SecondPanel Button',
                handler: 'SecondButtonClick'
            }]
        });


        Ext.define('MainPanel', {
            extend: 'Ext.panel.Panel',
            initComponent: function() {
              var me = this;
              me.items = [
                  Ext.create('FirstPanel', {
                      mainView: me
                  }),
                  Ext.create('SecondPanel')
              ]
              me.callParent();
            }
         });

这篇关于从FormController中访问功能,即可快速创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆