Ext Stores are asynchronous by default - your code continues to run while
the store waits on the response from the server.  Try rewriting your code
like so:

Ext Stores are asynchronous by default - your code continues to run while
the store waits on the response from the server.  Try rewriting your code
like so:

var zoomstore = new Ext.data.Store({
    autoLoad:true,
    proxy: new Ext.data.HttpProxy({ url:"/countries", method:"GET" }),
    reader: new Ext.data.JsonReader({
        root: 'counties',


        totalProperty: 'total',


    }, [{
        name: 'countyname'
    }]),
    listeners: {
        'load': function() {
            Ext.Msg.alert('etat', zoomstore.getCount())
        }
    }
});

This adds a function as a "listener" which Ext will use when the load has
actually completed.  If you are planning to work with ExtJS or browser-based
JavaScript in general I would suggest that you read up on event-driven
programming.  http://en.wikipedia.org/wiki/Event-driven_programming is a
good start.

--
David Winslow
OpenGeo - http://opengeo.org/

On Fri, Mar 18, 2011 at 4:52 PM, Jude Mwenda <[email protected]> wrote:
Hi,
I have created this on app on django that lists fields from the database.
Say countries app, added to admin. I have a view
http://localhost:8000/countries that returns a json string of the countries
in the database. I would like to load it onto a jsonreader store with little
success. Attaches is my ext js script to do so. Any pointers on what i am
doing wrong?

var zoomstore = new Ext.data.Store(
{
autoLoad:true,
proxy: new Ext.data.HttpProxy(
{
url:"/countries",
method:"GET",
}),
reader: new Ext.data.JsonReader(
{
root: 'counties',
totalProperty: 'total',
}, [{name: 'countyname'}])
 });
datesStore.load();
 Ext.Msg.alert('etat',zoomstore.getCount().toString());

On Fri, Mar 18, 2011 at 4:52 PM, Jude Mwenda <[email protected]> wrote:

> Hi,
> I have created this on app on django that lists fields from the database.
> Say countries app, added to admin. I have a view
> http://localhost:8000/countries that returns a json string of the
> countries in the database. I would like to load it onto a jsonreader store
> with little success. Attaches is my ext js script to do so. Any pointers on
> what i am doing wrong?
>
> var zoomstore = new Ext.data.Store(
> {
> autoLoad:true,
>  proxy: new Ext.data.HttpProxy(
> {
> url:"/countries",
>  method:"GET",
> }),
> reader: new Ext.data.JsonReader(
>  {
> root: 'counties',
> totalProperty: 'total',
>  }, [{name: 'countyname'}])
>  });
>  datesStore.load();
>  Ext.Msg.alert('etat',zoomstore.getCount().toString());
>
> The alert returns 0; meaning the store is not being loaded. Any pointers on
> what i am doing wrong. I am using the django serialiser for the view. which
> is
>
>
>  data = serializers.serialize('json', Country.objects.all(),
> fields=('id','countyname'))
> return HttpResponse(data)
>
>
> Please help.
>

Reply via email to