1. #1
    Sencha User
    Join Date
    Oct 2012
    Location
    Toulouse
    Posts
    60
    Vote Rating
    0
    Answers
    7
    novadys-sbu is on a distinguished road

      0  

    Default Answered: Passing controller to view problems

    Answered: Passing controller to view problems


    Hello everyone

    So I need a button in my mobile app to download a document.
    My problem is with the binding between my view and my controller.
    It seems that quite a few people have had this problem. Is there any way out ?
    Here is my code :

    In my view I have a button like so
    Code:
    {
                        id: 'downloadButton',
                        xtype: 'button',
                        scope: this,
                        text: 'Download',
                        handler:function(){
                            Ext.Msg.alert("Download button tapped");
                            //CALL CONTROLLER HERE ???
                        }
                        }
    And this is my controller :
    Code:
    Ext.define('documind.controller.DocumentController',{    //Init params
        extend: 'Ext.app.Controller',
        stores: ['Archives'],
        models: ['Viewer'],
        views: ['Viewer'],
        singleton: true,
        alias: 'DocumentController',
        
        /**
        * Main function of the controller
        * It redirects the user event to the corresponding function
        * Created : 30-12-12
        * Author : Sarah Burrell
        */
        init:function(){
             this.control({
                'viewViewer':{
                    downloadButton : this.downloadDocument
                }                
             });
        },
        downloadDocument: function(){
            console.log("Download document");
        } 
        
    });

    If anyone has any ideas I will be very very grateful !!

    Sarah

  2. Because downloadButton is an Ext component so its event can be catched by controller.
    Code:
    {
        id: 'downloadButton',
        xtype: 'button',
        scope: this,
        text: 'Download',
    //  handler:function(){ <- no need
    //      Ext.Msg.alert("Download button tapped");
    //      //CALL CONTROLLER HERE ???
    //  }
    }
    Controller
    Code:
        init:function(){
             this.control({
    //            'viewViewer':{
    //                downloadButton : this.downloadDocument
    //            }
                '#downloadControl': {
                    click: this.downloadDocument
                }
            });
        },

  3. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    115
    Answers
    346
    vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold vietits is a splendid one to behold

      0  

    Default


    Because downloadButton is an Ext component so its event can be catched by controller.
    Code:
    {
        id: 'downloadButton',
        xtype: 'button',
        scope: this,
        text: 'Download',
    //  handler:function(){ <- no need
    //      Ext.Msg.alert("Download button tapped");
    //      //CALL CONTROLLER HERE ???
    //  }
    }
    Controller
    Code:
        init:function(){
             this.control({
    //            'viewViewer':{
    //                downloadButton : this.downloadDocument
    //            }
                '#downloadControl': {
                    click: this.downloadDocument
                }
            });
        },

Thread Participants: 1

Tags for this Thread