tags:

views:

243

answers:

1

I have problems getting data from grails using extjs. My Grails controller code is:

   def getElements = { 
        def json =   [
         "firstName": "John",
         "lastName": "Smith",
         "age": 25,
         "address": [
             "streetAddress": "21 2nd Street",
             "city": "New York",
             "state": "NY",
             "postalCode": "10021"
         ],
         "phoneNumbers": [
             [ "type": "home", "number": "212 555-1234" ],
             [ "type": "fax", "number": "646 555-4567" ]
         ],
         "newSubscription": false,
         "companyName": null
        ] as JSON

        response.setHeader('Content-disposition', 'filename="json"')
        response.contentType = "text/json";
        render (json) as JSON
        }

When I browse to .../controller/getElements I do get an JSON Element as download.

Actually, I want to use this json in ExtJS. My ExtJS code:

...
var jsonstore = new Ext.data.JsonStore({
   url: "datenabruf/getElements",
   fields: [ 'firstName','lastName'],
   paramNames: { start : "offset", limit :"max", sort : "sort", dir : "order" }
});
alert(jsonstore.getTotalCount());

The problem is, that I get 0 elements. Am I missing some parameters?

A: 

Solved!

i just had to load the store afterwards.

jsonstore.load({callback: function(r) { alert("juhu"); }})