Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send parameters from a view to other in Sencha Touch 2 using a controller

I'm just migrating from Sencha Touch 1.x to Sencha Touch 2 and I can't find a way to pass parameters between views.

Lets say I have to views: Place (a list with all the places) PeopleAtPlace (A list of the people for each place)

Now what I need to do is to pass the id of the place that is pressed to the peopleatplace view so it can get the people for that specific view.

I've been reading Sencha's documentation but it's pretty confusing to me.

Could somebody please help me? A code snippet would be great help to me.

like image 249
Multitut Avatar asked Dec 01 '25 09:12

Multitut


1 Answers

Controllers can be the glue between different views. I don't know what kind of views you exactly have, but the following code can serve as a base:

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);
    }
});
like image 95
tpolyak Avatar answered Dec 03 '25 07:12

tpolyak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!