We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    Hi,

    I’m completely stuck with my JsonStore. It will not load. I have the following store defined:

    		var dstore = new Ext.data.JsonStore({
    			url: Tariffs.config.connector_url
    			,baseParams: {
    				action: 'mgr/calendar/getmonth'
    			}
    			,fields: ['id', 'year', 'month', 'src']
    			,root: 'months'
    		});
    		dstore.load();
    		alert(dstore.getTotalCount());
    


    I have simplified the getmonth.php routine to the point that it just returns the following Json string:
    error_log('About to return Json string');
    return '{"months":[{"id":0,"month":"10","year":"2010","src":""},{"id":1,"month":11,"year":"2010","src":""}]}';
    


    I know the getmonth.php is called as I see the log statement. But after that no data appears in the store. The alert(dstore.getTotalCount()) replies with 0...

    Anybody any ideas?
      MODx Revolution / MAMP / OS X
      • 26903
      • 1,336 Posts
      Well, ExtJS does say this about the load method :-
      Important: loading is asynchronous! This call will return before the new data has been loaded. To perform any post-processing where information from the load call is required, specify the callback function to be called, or use a ’load’ event handler.
      So it’s probably still getting the data when your alert is called.
        Use MODx, or the cat gets it!
        • 27519
        • 275 Posts
        Spot on!

        I added a listener for the load event:
        			,listeners: {
        				'load': {fn:function() {
        					alert(dstore.getTotalCount());
        				}, scope:this}
        			}
        


        And it shows up with a count of 2.

        I read about the async load but could not find anything in the way store loading is handled by MODx manager widgets. Probably should have tried that before posting here... embarrassed

        Anyway, you helped me out!! Thanks!
          MODx Revolution / MAMP / OS X
          • 26903
          • 1,336 Posts
          No probs, I’m secretly noting down everything your doing here BTW for my future ref!
            Use MODx, or the cat gets it!
            • 27519
            • 275 Posts
            grin
              MODx Revolution / MAMP / OS X
              • 27519
              • 275 Posts
              Wahoooo!!!! It’s a thing of beauty grin

              My availability calendar works like a charm, with Json store and online/real time sync with backend.

              Thanks to Shaun and shamblett for their kind help!
                MODx Revolution / MAMP / OS X
                • 1778
                • 659 Posts
                Congratulations !!! laugh
                I’ll have to do something similar during the next weeks... I’ll refer a lot to your posts here... and probably will have to ask for your help on some points... (don’t really know what points at this time, but i’m pretty sure i will face some problems, issues, questions...)
                Cheers
                  • 27519
                  • 275 Posts
                  Hi Anso,

                  Feel free to ask or PM me if you’re stuck.
                    MODx Revolution / MAMP / OS X
                    • 4971
                    • 964 Posts
                    Yes, I am also following your work and explorations...
                    you are opening the trail for the rest of us...
                    thanks!
                      Website: www.mercologia.com
                      MODX Revo Tutorials:  www.modxperience.com

                      MODX Professional Partner
                      • 27519
                      • 275 Posts
                      Well, thanks but the honors go really to Shaun who put up with my silly syntax errors.

                      I must say that although complicated, the MODx manager environment is a joy to work with. Solid as rock and very well thought out.

                        MODx Revolution / MAMP / OS X