【问题标题】:Send parameters from a view to other in Sencha Touch 2 using a controller使用控制器将参数从 Sencha Touch 2 中的视图发送到其他视图
【发布时间】:2012-09-12 20:01:45
【问题描述】:

我刚刚从 Sencha Touch 1.x 迁移到 Sencha Touch 2,我找不到在视图之间传递参数的方法。

假设我必须查看: 地点(包含所有地点的列表) PeopleAtPlace(每个地方的人员列表)

现在我需要做的是将按下的地点的 id 传递给 peopleatplace 视图,以便它可以获取该特定视图的人员。

我一直在阅读 Sencha 的文档,但这让我很困惑。

有人可以帮助我吗?一个代码 sn-p 对我有很大帮助。

【问题讨论】:

    标签: model-view-controller sencha-touch-2


    【解决方案1】:

    控制器可以成为不同视图之间的粘合剂。不知道你具体是什么观点,下面的代码可以作为基础:

    Ext.define('MyApp.controller.TestController', {
        extend : 'Ext.app.Controller',
    
        config : {
            views : [  // you need to list all views your controller will use
                'Place', 
                'PeopleAtPlace'
            ],
    
            refs : {
                place : 'place',  // ComponentQuery used to find the view e.g. xtype, id, etc of the view 
                peopleAtPlace : 'peopleAtPlace'
            },
    
            control : {
                place : {
                    select : 'onPlaceSelected' // use the appropriate event 
                }
            }
        },
    
        onPlaceSelected : function (view, record) {
            var peopleAtPlaceView = this.getPeopleAtPlace(); // generated by Sencha from the ref property
    
            // now you have the reference to the target view, you can put your logic here
            peopleAtPlaceView.doSomething(record);
        }
    });
    

    【讨论】:

    • 好问题和好答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多