Results 1 to 3 of 3

Thread: Global Variable with MVC

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    15
    Vote Rating
    0
      0  

    Default Global Variable with MVC

    Hi,

    I have a variable in my index.js file and I need to pass that variable to my store in store.js file, and this is an application with the MVC architecture.

    Thanks for your help!.

  2. #2
    Sencha User
    Join Date
    Jan 2011
    Posts
    24
    Vote Rating
    -1
      0  

    Default

    In your app controller (main controller) set up a reference to the items you need (see the docs). Ext will then generate get methods for those references that you can then access from your other controllers by means of this.app.getGlobalVariable().

    Example:
    App Controller
    Code:
    Ext.application({
    name: 'Portal',
    appFolder: 'Scripts/portal',
    controllers: ['Main'],
    models: ['ModelWithGlobalVariable'],
    launch: function() { Portal.app = this; }
    });
    Controller where work is being done
    Code:
    this.application.getModelWithGlobalVariable().GlobalVariable = value;
    Hopefully that leads you down the right path. I think if the variable is truly global you should be able to access it directly from the store I believe. I set up a global grid filter in my app.js file that I can then access from any file in my project if I so desire.

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Posts
    15
    Vote Rating
    0
      0  

    Default

    Thank you that i going to use it later.
    This is my case:

    i enter to my web application with an url like this:
    http://localhost/TCUVapp/index.html?var1=9&var2=873

    index.html
    Code:
    <html>
        <head>
            <title>TCUV</title>
    
            <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
    
            <script type="text/javascript" src="extjs/ext-debug.js"></script>
    
            <script type="text/javascript" src="app.js"></script>
        </head>
        <body></body>
    </html>
    app.js in this file i obtain the variables from the url
    Code:
    Ext.application({
        name: 'TCUV',
        appFolder: 'app',
        controllers: ['Recomendaciones'],
        launch: function () {
    
            var urlinicial = location.search.substring(1);
            var var1 = Ext.Object.fromQueryString(urlinicial).var1;
    
            Ext.create('Ext.container.Viewport', {
                layout: {
                    type: 'border',
                    padding: 5
                },
                defaults: {
                    split: true
                },
                items: [{
                    region: 'west',
                    collapsible: true,
                    title: 'Men',
                    split: true,
                    width: '15%'
                }, {
                    region: 'center',
                    layout: 'border',
                    border: false,
                    items: [{
                        region: 'center',
                        items: [{
                            xtype: 'recomendacionlist'
                        }]
                    }]
                }]
            });
        }
    });
    I need to past the var1 to my file with the store. I have this in
    app/store/recomendaciones.js
    Code:
    Ext.define('TCUV.store.Recomendaciones', {
        extend: 'Ext.data.Store',
        model: 'TCUV.model.Recomendaciones',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            api: {
                read: 'http://localhost/WsTCUV/Service.asmx/GetRecomendaciones?var1=9&var2=873'
            },
            headers: {
                'Accept': 'application/json, text/javascript, *=*',
                'Content-Type': 'application/json; charset=utf-8'
            },
            reader: {
                type: 'json',
                root: 'd'
            },
        }
    });
    In my store i have the value of var1 and var2 with a static value but i need the value for var1 and var2 from the url of the beginning (http://localhost/TCUVapp/index.html?var1=9&var2=873).

    Thanks for your help!.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •