Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:56:07+00:00 2026-06-03T10:56:07+00:00

I have a global variable which needs to be initialized when the store is

  • 0

I have a global variable which needs to be initialized when the store is loaded and needs to use that value in another store as follows

var cp = 0;

Ext.onReady(function() {
    Ext.define('Init', {
        singleton: true,
        cp: 0
    });

    Ext.define('loggedUserList', {
        extend: 'Ext.data.Model',
        fields: [
            'id',
            'name'
        ]
    });

    loggedUser = Ext.create('Ext.data.Store', {
        model: 'loggedUserList',
        autoLoad: true,
        proxy: {
        type: 'ajax',
        url: url+'/lochweb/loch/users/getLoggedUser',
        reader: {
            type: 'json',
            root: 'provider'
        },
        listeners: {
            load: function(loggedUser) {
                Init.cp = loggedUser.getAt(0).data.id;
            }
        }
    }); 
});

I am using the value of cp in another url as follows: url: url + '/lochweb/loch/vocabulary/getVocabularyByProvider?providerId=' + Init.cp,

Ext.define('vocbList', {
    extend: 'Ext.data.Model',
    fields: [
        {
            name: 'id',
            mapping: 'id'
        },
        {
            name: 'code',
            mapping: 'code'
        }
    ]
});

var vocabulary = Ext.create('Ext.data.Store', {             
    model: 'vocbList',
    autoLoad: true,
    proxy: {
        type: 'ajax',                   
        url: url+'/lochweb/loch/vocabulary/getVocabularyByProvider?providerId='+Init.cp,                    
        reader: {
            type: 'json',
            root: 'Vocabulary'
        }
    }
});

but its value is still 0. I tried using(cp, Init.cp). How to assign its value form store so that it can be reused?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:56:17+00:00Added an answer on June 3, 2026 at 10:56 am

    Store loads data asynchronously, so you can’t be sure that Init.cp will be initialized with a new value before the other store is been loaded.
    Try with this:

    var cp=0;
    
    Ext.onReady(function(){
    Ext.define('Init', {
        singleton: true,
        cp: 0
    });
    
    Ext.define('vocbList', {
                extend: 'Ext.data.Model',
                fields: [
                    { name: 'id', mapping: 'id' },
                    { name: 'code', mapping: 'code' }
    
                ]
            });
    
    
    
        var vocabulary = Ext.create('Ext.data.Store', {             
            model: 'vocbList',
            proxy: {
                type: 'ajax',                                   
                reader:  {
                    type: 'json',
                    root: 'Vocabulary'
                }
            }
    
    Ext.define('loggedUserList', {
                    extend: 'Ext.data.Model',
                    fields: ['id','name']
                });
    
                loggedUser = Ext.create('Ext.data.Store', {
                    model: 'loggedUserList',
                    autoLoad: true,
                    proxy: {
                        type: 'ajax',
                        url : url+'/lochweb/loch/users/getLoggedUser',
                        reader: {
                         type: 'json',
                            root: 'provider'
                        }                   
                    },
                    listeners: {
                        load:function(loggedUser){
                            Init.cp = loggedUser.getAt(0).data.id;
                            vocabulary.getProxy().url = url+'/lochweb/loch/vocabulary/getVocabularyByProvider?providerId='+Init.cp;
                            vocabulary.load();
                        }
                    }
    
                }); 
    });
    

    As you can see, you have to set the url of the vocabulary proxy dynamically when the first store is just loaded and then load the store.

    Cyaz

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a program that initializes a global variable for use by threads,
If i have global variable in A.dll, that depends on global variable in B.dll
I have a global variable that is an instance of my custom class. How
I have a vector declared as a global variable that I need to be
I am developing a shared library(.so) and dll. I have a global variable which
I am working with code that has a global static variable (which is an
which is the cleanest way to use something like a global variable? Normally, using
I am trying to design header only library, which unfortunately needs to have global
I have global static variables in a C library, which generate exceptions in a
I have a global pointer variable char* pointer = new char[500]; /* some operations...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.